What if you have two instances of the same script that are each trying to reference each other's enums. Here's an example
projectile.js :
enum projectileType = {laser, missle, mine}
var theType : projectileType.laser;
onCollisionEnter(other : Collision) {
if (other.gameObject.GetComponent(projectile).theType == projectileType.laser) {
//do something
}
}
This never seems to work for me, and many of the hacks fail when I add '#pragma strict' to the code. For some reason, the compiler thinks that other.gameObject.GetComponent(projectile).projectileType is of type System.object, and therefor cannot be compared to projectileType. If you are having this problem to, try this:
onCollisionEnter(other : Collision) {
if (other.gameObject.GetComponent(projectile).theType.ToString() == "laser") {
//do something
}
}
Obviously not ideal, but it worked for me. Let me know if it works for you.
I know it's old, but let's leave the answer here:
ReplyDeleteenum ProjectileType {laser, missle, mine}
var theType : ProjectileType = projectileType.laser;