- Home /
Question by
[DJ]Creepz · Jul 03, 2012 at 12:56 PM ·
enumoncontrollercolliderhit
how can use the names of a enum variable in an if statement
i have a character controlled model and 5 terrain.. at start.. the model start to land at terrain 1..so once the model land to the terrain.. it will recognize that this terrain will be used.
so I'd make an enum containing this:
public enum _myTerrains {
T1,
T2,
T3,
T4
}
public _myTerrains myter;
and then in my model i'm using OnControllerColliderHit()
void OnControllerColliderHit (ControllerColliderHit hit) {
contactPoint = hit.point;
if(hit.collider.tag == "T1")
{
Debug.Log("agaegae");
}
}
now i want to use the enum variable at this code:
if(hit.collider.tag == myter.T1){
}
but it won't work.. please help me
Comment
Answer by Wolin · Jul 03, 2012 at 01:48 PM
You have to change it to string. Just like this.
if(hit.collider.tag == myter.T1.ToString())
Answer by Kryptos · Jul 03, 2012 at 01:47 PM
You must convert the enum value into a string. Try this:
if(hit.collider.tag == myter.T1.ToString()){
}
Reference: Enum.ToString Method (System)