- Home /
Error in script
I made a scipt but it still finds errors in it. Don't know why.
var object1 : GameObject;
// enables ConstantForce on object1 if it has InTriggerY true.
function Update()
{
if object1.GetComponent("RigidbodyTrigger").InTriggerY = true {
object1.GetComponent("Rigidbody").useGravity = false;
object1.GetComponent("ConstantForce").enabled = true;
} else {
if object1.GetComponent("RigidbodyTrigger").InTriggerY = false {
object1.GetComponent("Rigidbody").useGravity = true;
object1.GetComponent("ConstantForce").enabled = false;
}
}
}
Comment
Answer by echofiend · Nov 11, 2012 at 06:41 AM
did you ever actually set the object1 to a game object?
you have to use
object1 = GameObject.Find("YOUR GAME OBJECT");
or specifically set it in the editor.
p.s. its fairly bad form(at least for me) to tell someone to "Try it in your unity" instead of supplying the error. There may be other things involved that you have in your build that no one else will have.
Yes, I know, sorry for that, but I didn't have much time so replied at least that to keep this thread going... Hmmm, yes, I did set the variable in the editor, if your asking for that...
Your answer
![](https://koobas.hobune.stream/wayback/20220613083647im_/https://answers.unity.com/themes/thub/images/avi.jpg)