hi i need help why does this script not work for me ?(I want it to do this when it touches these 4 things so an object is created) Thank you in advance for your answer Code (CSharp): void OnTriggerStay(Collider other) { if (other.gameObject.tag == "Wood" & other.gameObject.tag == "Cloth" & other.gameObject.tag == "Resin" & other.gameObject.tag== "hammer") { Instantiate(prefab, spawn.position, spawn.rotation); } else { }
Just so you know, AND in C# is &&, not &. AND is not what you want in this case, though. You probably meant OR, which is ||.
In the above code, any give GameObject will NEVER be all of those tags at once. You will need to implement some type of persistent "I am touching X" so that you have another script decide "Am I touching all items necessary?" Ideally, start with a tutorial for a crafting game that does this type of thing. It's WAY too complex to type out all the necessary steps here.
Code (CSharp): if ( other.gameObject.tag == "Wood" || other.gameObject.tag == "Cloth" || other.gameObject.tag == "Resin" || other.gameObject.tag == "hammer") { Instantiate(prefab, spawn.position, spawn.rotation); } else { }
I changed it to triggerenter, it is no longer an unlimited object, but when I place the first object out of four, a new one is created why ?
I wrote: It will be several different scripts set up precisely just so: one to track the items, one to sense the items, one to trigger the crafting when conditions are appropriate.