- Home /
Operator issue in "then" statment.
The code is supposed to instantiate the product when the player clicks and there's enought gold, then remove some gold. (I'm a novice programer)
var Gold:int;
var product : Rigidbody;
function Update () {
Gold = 15;
if (Input.GetButtonDown("Fire1") && Gold > 10) {
Instantiate(product, transform.position, transform.rotation);
Gold--;
}
}
Comment
I don't think you can Instantiate a Rigidbody. Try instantiating a GameObject ins$$anonymous$$d.
You can instantiate a Rigidbody: [code] Rigidbody clone; clone = Instantiate(product, transform.position, transform.rotation) as Rigidbody; [/code]
Answer by DaveA · Feb 14, 2012 at 11:17 PM
You are setting Gold = 15 every frame. The comparison to 10 will always be true. Move Gold=15 to a Start function.
If it's a constant value, you might as well initiate it in the header? Or keep it as a public variable to be tweaked later.
Your answer
![](https://koobas.hobune.stream/wayback/20220613064059im_/https://answers.unity.com/themes/thub/images/avi.jpg)