Пример #1
0
    //Checks for a touch on the enemy and responds by deducting health
    void OnTouch()
    {
        //Raycast
        Ray          ray = Camera.main.ScreenPointToRay(m_touch);
        RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity);

        //If there is a hit
        if (hit)
        {
            //Checkt the gameObject's tag
            if (hit.collider.gameObject.tag == "Enemy")
            {
                //Get access to the gameObject's enemyManager script
                enemyManager = hit.collider.gameObject.GetComponent <EnemyManagerScript>();
                // - health
                currentHealth = enemyManager.GetHealth();
                currentHealth--;
                //Set the new health
                enemyManager.SetHealth(currentHealth);


                //Check if enemy is dead
                if (enemyManager.GetHealth() <= 0)
                {
                    enemyManager.SetIsDead(true);
                }

                //If enemy is dead reset
                if (enemyManager.GetIsDead() == true)
                {
                    //Reset the enemies position
                    hit.collider.gameObject.transform.position = enemyManager.GetSpawnPos();
                    //Reset enemies health
                    enemyManager.ResetHealth();
                    //Set enemy to alive
                    enemyManager.SetIsDead(false);
                }
            }
        }
    }
Пример #2
0
 void Spawn()
 {
     //reset the enemies position
     gameObject.transform.position = enemyManager.GetSpawnPos();
 }