- Home /
help for check/uncheck "IsTrigger" from a Gameobject
hi guys from unityAnswer i need a little help for check/uncheck "IsTrigger" button from a box collider put in a GameObject.
i have try this script but idk why don't work:
//start code:
function Update() { collider.isTrigger.enabled = false; }
//end code.
thx for reading.
Answer by Zib Redlektab · Jul 08, 2011 at 03:07 PM
Just make it
collider.isTrigger = false;
not isTrigger.enabled.
Answer by senluc · Jul 08, 2011 at 04:10 PM
this is right?
i put this script in my gameobject that i want to check /uncheck istrigger?
function Update() {
if (Input.GetKeyDown("f")) {
// toggle istrigger
collider.isTrigger = false;
}
}
Oky guys work!!! But only 1 time,if i repress "f" don't recheck is trigger
collider.isTrigger is either true or false. If you do collider.isTrigger = !collider.isTrigger; you make it the opposide. Use that. And once again, don't post answers as comments. If you have posted this as a comment the people who have posted answers would've gotten a warning you commented.
senluc I think you need to start learning better scripting for that go here: http://unity3d.com/support/documentation/ScriptReference/index.html and any think you need to know just put the name on the search bar(like searching trigger)
thx Uriel,but i'm not a novice , but this is really strange i know that "collider.isTrigger is either true or false,but if i repress the same button don't recheck: if "true" i press the button "f" change to false,but if i repress the same button stay on false.
i have solved my problem thx guys,and sorry for problem that i have caused about posts.
Answer by senluc · Jul 08, 2011 at 03:31 PM
don't work i need this:
I don't understand, can't you just check the box? collider.isTrigger = false or true should change the collider to be a trigger or not, programmatically. I'm going to need more info if I'm going to help :P
well collider.isTrigger = true; makes it true again.. Zib's answer is the correct one.
Answer by senluc · Jul 08, 2011 at 04:05 PM
guys i need that when i press a button "f" the gameobject that have "the box collider" uncheck the button is trigger
stop answering your own question with comments please. Zib answered your original question, so you should accept it.
If you, in addition, would like to ask how you make a piece of code be run by the press of a key, I would suggest googling - because that has been answered in depth tons of times.
Answer by FilipeGevaerd · Mar 01, 2014 at 02:13 PM
use this code to toggle on/off the trigger:
function Update() {
if (Input.GetKeyDown("f")) {
//toggle istrigger
collider.isTrigger = !collider.isTrigger;
}
}
Your answer
Follow this Question
Related Questions
Box Collider isTrigger making my car jump 1 Answer
Ignore Collision after passing a collider 1 Answer
Help with OnTriggerEnter issue 3 Answers
How can I get an OverlapBox with the exact same size and position as a BoxCollider? 1 Answer
How to get Closest Edge/Vertex Position of a 3D BoxCollider? 1 Answer