Exemplo n.º 1
0
        void Update()
        {
            Vector3 newPosition = transform.position;

            newPosition += Velocity * Time.deltaTime;

            Lifetime -= Time.deltaTime;
            if (Lifetime < 0)
            {
                Destroy(gameObject);
            }

            short tileX = (short)Mathf.FloorToInt(newPosition.x);
            short tileZ = (short)Mathf.FloorToInt(newPosition.z);

            TileMap tileMap = GameManager.Instance.TileMap;

            if (tileMap.HasBlock(tileX, tileZ) || GameManager.Instance.IsOutOfBounds(tileX, tileZ))
            {
                if (ColorType != null)
                {
                    TryPlaceAfterHitting(tileX, tileZ);
                }
                else
                {
                    TryTriggerChainReaction(tileX, tileZ);
                }
                Destroy(gameObject);
            }

            Ray ray = new Ray(LastPosition, newPosition - LastPosition);

            RaycastHit[] hits = Physics.RaycastAll(ray, (newPosition - LastPosition).magnitude);

            foreach (RaycastHit hit in hits)
            {
                EnemyBehaviour enemyBehaviour = hit.transform.gameObject.GetComponent <EnemyBehaviour>();
                if (enemyBehaviour != null)
                {
                    if (EnemiesPassed < MaxEnemyPasses)
                    {
                        if (ColorType == null)
                        {
                            SetColor(enemyBehaviour.ColorType);
                            killEnemy(enemyBehaviour);
                        }
                        else if (enemyBehaviour.ColorType == ColorType)
                        {
                            GameManager.Instance.AwardPoints(1);
                            killEnemy(enemyBehaviour);
                        }
                    }
                }
            }

            transform.position = newPosition;
            LastPosition       = transform.position;
        }
Exemplo n.º 2
0
 private void killEnemy(EnemyBehaviour enemy)
 {
     if (enemy.HitByBullet(this))
     {
         Destroy(gameObject);
     }
     EnemiesPassed++;
     Destroy(enemy.gameObject);
 }