c# - unity OnTriggerStay2D() for two triggers -
i using unity 5 c# , have gameobject 2 trigger colliders 1 of them in different location. need able use ontriggerstay2d , ontriggerenter2d them need find trigger being entered. right if enter 1st(polygon) trigger ontriggerenter activates 2nd(box). how can tell 2 colliders apart???
public void ontriggerenter2d(collider2d other) //2nd collider trigger { if (other.tag == "player") { found = true; //if player in shooting range idle = false; } } public void ontriggerstay2d(collider2d other) //1st collider trigger { if (found != true) { if (other.tag == "player") { shield = true; idle = false; } } } public void ontriggerexit2d(collider2d other) //2nd collider trigger { if (other.tag == "player") { found = false; shield = false; shooting = false; idle = true; } }
i have tried making 1st trigger public void ontriggerstay2d(polygoncollider2d other) says "this message parameter has of type: collider2d message ignored."
what trying have polygon trigger in front of gameobject , different box trigger closer gameobject when go near gameobject enter 1st trigger , puts shield when close (within shooting range of it) put shield down , start shooting you.
well collider2d detects types of 2d colliders. doesn't matter if it's polygon or box. documentation suggestions doesn't need public or private. takes collider2d it's argument however.
for debugging purposes why not use print?
print("you've entered trigger function");
also wouldn't use 2 different trigger colliders on same gameobject. why not make 2 separate gameobjects can have more thorough detection. each gameobject own trigger collider can have different tags.
if have use 2 trigger colliders on 1 object. isn't best idea. use shapecount determine 1 it's hitting. although said warrant against doing 2 trigger colliders on same object when whatever you're trying can easier on 2 separate objects.
however links aren't prohibited think. watch , study these videos. they're useful explaining engine , aren't long. https://unity3d.com/learn/tutorials/modules/beginner/2d have video explaining 2d colliders.
Comments
Post a Comment