Example #1
0
        //COLLISION

        void OnTriggerEnter(Collider other)
        {
            //If is a crawler unit
            if (other.name.Contains("Crawler"))
            {
                //Get the crawler unit
                CrawlerUnit currentCrawler = other.gameObject.GetComponent <CrawlerUnit>();

                //if its an enemy
                if (currentCrawler.currentTeamName != currentTeamName)
                {
                    //If the enemies in range doesnt contain this transform
                    if (!enemiesInRange.Contains(other.transform))
                    {
                        //Add this transform
                        enemiesInRange.Add(other.transform);

                        //If its the first enemy
                        if (enemiesInRange.Count == 1)
                        {
                            //Choose a different target
                            ChooseTarget();
                        }

                        //if current crawler doesnt contain this tower, add it
                        if (!currentCrawler.towers.Contains(this) && !currentCrawler.isDying)
                        {
                            currentCrawler.towers.Add(this);
                        }
                    }
                }
            }
        }
Example #2
0
        void OnTriggerExit(Collider other)
        {
            //If is a crawler unit
            if (other.name.Contains("Crawler"))
            {
                //Get the crawler unit
                CrawlerUnit currentCrawler = other.gameObject.GetComponent <CrawlerUnit>();

                //If the enemies in range contains this transform
                if (enemiesInRange.Contains(other.transform))
                {
                    //Remove it
                    enemiesInRange.Remove(other.transform);

                    //Choose a different target
                    ChooseTarget();

                    //Tell the tower to aim elsewhere
                    if (currentCrawler.towers.Contains(this))
                    {
                        currentCrawler.towers.Remove(this);
                    }
                }
            }
        }
Example #3
0
        //COLLISION

        void OnTriggerEnter(Collider other)
        {
            //If its a Crawler
            if (other.gameObject.name.Contains("Crawler"))
            {
                //Sets target as Crawler
                target = other.gameObject.GetComponent <CrawlerUnit>();

                //if crawler is from opposite team
                if (target.currentTeamName != owner.currentTeamName)
                {
                    //Delivers damage to the unit
                    target.ReceiveDamage(damagePoints);

                    //Destroy proyectile
                    Die();
                }
            }
        }