//on collision
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "AllyProjectile")          //if the projectile is an ally projectile

        //find the projectiles data
        {
            ProjectileData hitData = other.gameObject.GetComponent <ProjectileData> ();

            //deal damage according to its data
            myHealthScript.takeDamage(hitData.getDamage());

            //if the projectile is DestroyOnHit destroy the projectile
            if (hitData.getDestroyOnHit())
            {
                Destroy(other.gameObject);
            }
        }
    }
Beispiel #2
0
    void OnTriggerEnter(Collider other)
    {
        Debug.Log("Touch");
        //if the main character collides with an enemy projectile
        if ((other.gameObject.tag == "EnemyProjectile") && hitBoxEnabled)
        {
            Debug.Log("Hit");

            //get data from the projectile
            ProjectileData hitData = other.gameObject.GetComponent <ProjectileData> ();

            //take damage based on the projectile data
            myHealthScript.takeDamage(hitData.getDamage());

            //if the projectile is to be destroyed on hit destroy it
            if (hitData.getDestroyOnHit())
            {
                Destroy(other.gameObject);
            }
        }
    }