- Home /
Question by
smirlianos · Jun 29, 2013 at 11:15 AM ·
colliderarraysetfalse
Set rigidbody to false
Hello!
I have this script that changes a variable in an array of objects. How can I set the rigidbody and collider of these objects to false as well?
var barricades = GameObject.FindGameObjectsWithTag("Bar");
for(var x in barricades)
{
var theScript = x.GetComponent.< Js_Bars >();
theScript.hitted = true;
}
Comment
Don't bother using the generic version of GetComponent in Unityscript; just do "`x.GetComponent(Js_Bars)`", which is slightly faster, and easier to type, but does exactly the same thing.
Best Answer
Answer by Travis-Bulford · Jun 29, 2013 at 12:36 PM
For the rigidbody you should be able to add the following code
if (x.rigidbody!=null){
x.rigidbody.active = false;
// For unity 4
x.rigidbody.detectionCollisions = false;
}
See http://docs.unity3d.com/Documentation/ScriptReference/GameObject-rigidbody.html
Warning the above code was just added here. Might be a typo or 10 :)
Your answer