- Home /
Destroy GameObject A or B
So, on this project I have a script (JS): #pragma strict function Start () { Destroy(GameObject.Find("cell1door")) || Destroy(GameObject.Find("cell2door"));
}
Now, I get an error with the the || part. Is there any way of fixing this where both have a 50% chance of being destroyed.
Answer by ExTheSea · May 12, 2013 at 07:09 PM
You can't use this syntax.
You have to do something like this:
function Start () {
if(Random.value >0.5)
Destroy(GameObject.Find("cell1door"));
else
Destroy(GameObject.Find("cell2door"));
}
Yes there is i updated my answer. I just used it becaue i thought you wanted to use it for that anyways.
Can you now please accept the answer to mark the question as solved.
Your answer
![](https://koobas.hobune.stream/wayback/20220613102106im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
What is wrong with my script? 1 Answer
Add force to GameObject 2 Answers
how to link objects in the inspector on load level 1 Answer
Unity get component help 1 Answer