2021-04-19 03:49:55 +00:00
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
2018-06-19 09:06:54 +00:00
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
2020-04-14 14:37:41 +00:00
using Stride.Engine ;
2018-06-19 09:06:54 +00:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
2020-04-14 14:37:41 +00:00
using Stride.Physics ;
2018-06-19 09:06:54 +00:00
namespace SpriteStudioDemo
{
public class EnemyCollisionScript : AsyncScript
{
public override async Task Execute ( )
{
var rigidbodyElement = Entity . Get < RigidbodyComponent > ( ) ;
var enemyScript = Entity . Get < EnemyScript > ( ) ;
while ( Game . IsRunning )
{
var collision = await rigidbodyElement . NewCollision ( ) ;
if ( collision . ColliderA . Entity . Name = = "bullet" & & ! rigidbodyElement . IsTrigger ) //if we are trigger we should ignore the bullet
{
var script = collision . ColliderA . Entity . Get < BeamScript > ( ) ;
script . Die ( ) ;
enemyScript . Explode ( ) ;
}
else if ( collision . ColliderB . Entity . Name = = "bullet" & & ! rigidbodyElement . IsTrigger )
{
var script = collision . ColliderB . Entity . Get < BeamScript > ( ) ;
script . Die ( ) ;
enemyScript . Explode ( ) ;
}
}
}
}
}