public override void OnCollision(LaserStraight laser)
 {
     // Trigger the hit event on the main enemy script
     if (enemyHealth != null)
     {
         enemyHealth.OnHit(laser.Power, laser.Color, laser.transform);
     }
     laser.Destroy();
 }
示例#2
0
        private void EvaluateScript(Rigidbody other)
        {
            // Attempt to retrieve the laser from a cache
            LaserStraight laser = null;
            IEnemy        enemy = null;

            if ((LaserCache.TryGetValue(other, out laser) == false) && (EnemyCache.TryGetValue(other, out enemy) == false))
            {
                // If not cached, but the rigidbody has the right tag, grab the laser component
                MovingObject script = other.GetComponent <MovingObject>();
                if (script is LaserStraight)
                {
                    // If successful, cache the laser
                    laser = (LaserStraight)script;
                    LaserCache.Add(other, laser);
                }
                else if (script is IEnemy)
                {
                    // If successful, cache the laser
                    enemy = (IEnemy)script;
                    EnemyCache.Add(other, enemy);
                }
            }

            // Check if retrieve the laser workd
            if (laser != null)
            {
                // Run the event
                OnCollision(laser);
            }
            if (enemy != null)
            {
                // Run the event
                OnCollision(enemy);
            }
        }
示例#3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="laser">Will always be set to an actual instance.</param>
 public abstract void OnCollision(LaserStraight laser);
 public override void OnCollision(LaserStraight laser)
 {
     ship.OnHit(laser.Power, laser.Color, laser.transform);
     laser.Destroy();
 }