Hey people!
My little project contains 7 different in-game states. I use tags to determine the state. One of the gameObjects reacts to 2 of these states out of the 7. What is the easiest way to do this…below is my current code:
void OnTriggerEnter(Collider other)
{
if (other.tag != “stateOne”)
{
I tried/Want to achieve:
void OnTriggerEnter(Collider other)
{
if (other.tag != “stateOne” || “stateTwo”)
{ …DEATH ENSUES
However this does not work, mentioning “Operator || can’t be used on type BOOL/STRING”
Any combinations of operators I can use to make my colliders only react to 2 of the 7 tags?
Cheers again!
To react to 2 tags…
if (other.tag == "stateOne" || other.tag == "stateTwo")
{
// other.tag is either "stateOne" or "stateTwo"
}
Jeff
1 Like
This works, thank you…
However as I only wanted the Collider to react to 2 of the 7 states, with this code it means I must:
I should have premised in saying this is a “death” script which OnTriggerEnter kills the player if their not in stateOne/Two
if (other.tag == “stateThree” || other.tag == “stateFour” || other.tag == “stateFive” || other.tag == “stateSix” || other.tag == “stateSeven”)
How would code like this effect performance? Is there a more efficient way to say “If not in these 2 states, proceed to script”?
Cheers!
Edit: Spelling.
if (other.tag != "stateOne" && other.tag != "stateTwo")
{
// other.tag is NOT "stateOne" or "stateTwo"
}
1 Like
Perfect, Gentleman and a Scholar you are good sir.