Esempio n. 1
0
 void OnCollisionEnter(Collision other)
 {
     if (ignoreLayers == (ignoreLayers | 1 << other.gameObject.layer))
     {
         return;
     }
     else
     {
         if (other.gameObject.GetComponent <hitTarget> () != null)
         {
             hitTarget target = other.gameObject.GetComponent <hitTarget> ();
             if (!target.gotHit)
             {
                 target.hit(damage);
             }
         }
         else if (other.gameObject == player.mainPlayer.gameObject)
         {
             player p = other.gameObject.GetComponent <player> ();
             p.hit(damage);
             Vector3 dir = other.contacts [0].point - gameObject.transform.position;
             dir = dir.normalized;
             other.gameObject.GetComponent <Rigidbody> ().AddForce(dir * knockbackForce);
         }
     }
 }
Esempio n. 2
0
 void OnTriggerStay(Collider other)
 {
     if (ignoreLayers == (ignoreLayers | 1 << other.gameObject.layer))
     {
         return;
     }
     else
     {
         if (other.GetComponent <hitTarget> () != null)
         {
             hitTarget target = other.GetComponent <hitTarget> ();
             if (!target.gotHit)
             {
                 target.hit(damage);
             }
         }
     }
 }