I'm trying to make a game where a rolling ball is created dynamically.
I think below code is correct, but every time i run the code, I get an error saying that Ball1 is has not been assigned.
I think I have to use created a prefab object, which was done by Asset->create->prefab and drag and drop an game object on to it, but I have no idea how to use it.
var Ball1 : GameObject;
function Update () {
print(Buttons.ball1Count);
if(Buttons.ball1Count > 0){
var test : Rigidbody = Instantiate(Ball1, Vector3(0,0,15), Quaternion(0,0,0,1));
test.GetComponent("prefab");
Buttons.ball1Count --;
}
}
If this works for you, I wouldn't mind an upvote either. :P Glad I could help.
– e-bonnevilleYes, it's because you're trying to Instantiate Ball1 as a rigidbody -- this won't work. If you change
– e-bonnevillevar test : Rigidbody = Instantiateto thisvar test : GameObject = Instantiatethe error will disappear.No problem, good luck with your project.
– e-bonneville