Collision Help

Why wont this work? its supposed to see if the type of ground is grass. and if its grass it changes the interger to one. then if its wood, change it to two. i couldnt find out how to get it to detect the tag to see if it was grass, so i just used a string in a seperate script. if you could remake it so it checks the tag that would be great!

var groundType : int;

function OnCollisionEnter(collision : Collision){
    if (collision.GetComponent(GroundTypeScript).GroundType == "Grass"){
      groundType = 1;
    }
 else if (collision.GetComponent(GroundTypeScript).GroundType == "Wood"){
       groundType = 2;
  }
}

To check by tag:

var groundType : int;

function OnCollisionEnter(collision : Collision){
    if (collision.gameObject.tag == "Grass")
      groundType = 1;
 else if (collision.gameObject.tag == "Wood"){
       groundType = 2;
  }
}

this should work if both objects have a collider (or character controller), not set to trigger…

the player probably should also have a rigidbody

for detailed info of what combos will/won’t send collision message see this link:

http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html

check out the matrix at the bottom, it should help…