Search Unity

Collision detection with tag not working

Discussion in 'Scripting' started by wilsonc911, Aug 28, 2014.

  1. wilsonc911

    wilsonc911

    Joined:
    Aug 8, 2014
    Posts:
    9
    I'm trying to use the following code:

    Code (CSharp):
    1. void OnTriggerEnter(Collider other) {
    2.         Debug.Log("We hit something!");
    3.         if (other.gameObject.tag == "Player" && other.gameObject.GetPhotonView().owner != gameObject.GetPhotonView().owner || other.gameObject.tag == "Zombie") {
    4.             other.gameObject.GetComponent<Health>().TakeDamage(25);
    5.             Debug.Log("We hit a zombie!");
    6.         }
    7.  
    8.         if (other.gameObject.tag == "Zombie") {
    9.             Debug.Log("Zombie");
    10.         }
    11.         //We didn't hit ourselves. Destroy the bullet.
    12.         if(other.gameObject.GetPhotonView().owner != gameObject.GetPhotonView().owner) {
    13.         PhotonNetwork.Destroy(gameObject);
    14.         }
    The only part that seems to work is it'll detect when it "We hit something!" but the tag detection isn't working. Any ideas? The gameObjects im colliding with are properly tagged.