- Home /
how to disable script using OnColliderEnter/ OnTriggerEnter ?
I have two cubes. If my fps passes through cubeA first, the script in cubeB will be disabled and if my fps passes through cubeB first then the script of cubeA will be disabled. How am I suppose to code this? Please help me!
Comment
Best Answer
Answer by Imankit · Feb 12, 2013 at 12:52 PM
//Write This on cubeB's script say ScriptB...
OnCollisionEnter(Collision col)
{
if(col.gameObject.name == "cubeA"){
col.gameObject.GetComponent<ScriptA>().enabled = false;
}
}
// Write This on cubeA's script say ScriptA...
OnCollisionEnter(Collision col)
{
if(col.gameObject.name == "cubeB"){
col.gameObject.GetComponent<ScriptB>().enabled = false;
}
}
Your answer
Follow this Question
Related Questions
How can I disable controls? 1 Answer
disable a script when a object is hidden? 1 Answer
Disabling THIS script from code 1 Answer
A do nothing script? 2 Answers
How do i disable a script from a different script? 5 Answers