- Home /
Using "collider.name" vaule to determine next move? C#
Heya Unity Answers, top of the morning to you.
Here's the deal, I've got a number of triggers in a row numbered from -13 to 13 (0 being in the middle) and when they are hit it'll log which number has been hit using >Debug.Log(collider.name);
void OnTriggerEnter(Collider other)
{
Debug.Log(collider.name);
}
Now lets say I take Triggers 1, 2 and 3 and call them Group A...and I take 4, 5 and 6 and call them Group B, would it be possible to do something like this?....
void OnTriggerEnter(Collider other)
{
Debug.Log(collider.name);
collider.name = new int = "Trigger Number"
if(Trigger Number = 1, 2 or 3)
{
Do GroupA stuff ();
}
if(Trigger Number = 4, 5 or 6)
{
Do GroupB stuff ();
}
}
In a nutshell I want it to look at the value of the collider.name and turn on groups that the number has been assigned too. For example Trigger 1 is hit, that turns on GroupA stuff...then Trigger 4 is hit which turns on GroupB stuff, etc.
Any help would be great thanks!
Answer by Slobdell · Aug 18, 2013 at 03:39 PM
Add a tag to each object the trigger/collider is attached to. Objects 1-3 eould have tag groupA, etc. That way you when it triggers you could still get the collider name and also the tag(groupA) and respond accordingly.
This is the easiest way. Remember that you must register the tags in the tag manager before using them, and that you can access the object tag directly with collider.tag
Your answer
![](https://koobas.hobune.stream/wayback/20220613112441im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can use FixedUpdate in Update? 1 Answer
OnTriggerExit2D doesnt work 0 Answers
MouseOver Doesn't work ON trigger 3 Answers
Animation playing other object animation 0 Answers
force trigger to detect at x time 0 Answers