|
In this tutorial it talks about assigning a type to a variable. Is this assigning the value of the variable? If not what is it for?
(comments are locked)
|
|
No, it's not assigning the value. Basically, when you declare a variable and specify the type, you're telling the Unity compiler what the variable can hold. In the tutorial, Will created a variable named thePrefab and said this variable can only store a GameObject in it. You'll also notice he didn't assign a value, a GameObject, in the script. He actually assigned a GameObject using the Inspector when he dragged the BouncyBox prefab, which is a GameObject, into the thePrefab variable. In the Inspector, Unity displays the thePrefab variable as The Prefab.
(comments are locked)
|
|
Answering jjpprogrammer's answer (which is actually a question in itself). I can't access the tutorial from here, but I assume it's doing this:
The reason they're doing that is so you can access the instance of thePrefab that has been instantiated. If you want to change the position (or any property of that object), you can't access it by using 'thePrefab.position' (for example), because it's a link to a prefab, and not an actual GameObject. For example:
Check out the script reference for Object.Instantiate() for more information. As I've commented above, you've actually asked a separate question inside an answer. Please keep questions as questions and answers as answers, as it helps to keep UnityAnswers easier to search/read for everyone.
(comments are locked)
|
|
Thanks! I have one more question. I think you might have answered this in your last answer but I am not sure . Why does he set the var instance to instantiate? I would think that assigning the instantiate to a variable would only set it to the variables value, not run it? Why not just say: var thePrefab : GameObject; function Start () {
} This should be posted as a separate question.
Sep 14 '10 at 12:20 AM
Marowi
(comments are locked)
|
