Is there a way, hopefully via JS, that you can create and check for a flag? What I have is a function that I call on collision. It works fine, but I do not want it to happen when it collides with certain objects. So is there a way to add a flag to check for before I call the function. Basically in pseudo-code “if object has flag, execute, else do nothing”? Thanks in advance.
Sure, you can do that. (Also, the language doesn’t really matter; the concepts will be similar regardless of what language you’re using.)
I’m not completely clear on the details of your question, but it sounds like you’re looking for a Boolean variable and an ‘if’ statement. If that doesn’t give you enough to go on, perhaps you could clarify your question a bit.
It has been answered. Thank you to RampantStudios. I will post the answer here in case anyone else hunts this down:
Next best thing, you can “Tag” Game Objects, this tagging lets you tell which kind of object they are.
Go into the Property Inspector, in the top left select the tagging, and hit add Tag. From there there will be an array of tags you can set. Create your own one, add the game object to that tag and on the collision code you check to see what tag it is.
//C# Collider (Change to OnTriggerEnter for triggers)
public void OnCollisionEnter(Collider other)
{
if(other.gameObject.tag == “YOURTAG”)
{
//DO CODE HERE
}
}