- Home /
Very simple script - why isn't it working?
I found a tutorial that I can actually follow and understand here http://www.untoldentertainment.com/blog/2010/12/23/dynamically-add-a-gameobject-to-the-scene-in-unity-3d/
It made sense and I felt like I was learning. I was ready to jump for joy with my first bit of functional code. I followed the code exactly, typing it manually and then saw the error messages in Unity.
It keeps asking me to add a semicolon at 5,26 Right in the middle of the Vector3 pos variable.
I copied and pasted the original code into a separate script and tried that but even the original script does the same thing. What's going on?
Thanks for reading.
The Code in question...
var myCube : GameObject;
function Start() { var pos : Vector3(0,0,0); var rot : Quaternion = Quaternion.identity; Instantiate(myCube, pos, rot); }
function Update() { }
Answer by robertbu · Mar 01, 2013 at 03:47 PM
The line should read:
var pos : Vector3 = Vector3(0,0,0);
You can also do:
var pos : Vector3 = Vector3.zero;
Excellent, thank you. Why was this? Was the example wrote at a time when scripts worked differently? Or was it just assumed that the reader would know to add that extra bit in? Thanks again :)
The type is not required. So if you take a close look, the line might have been:
var pos = Vector3(0,0,0);
If this answered your question, click the checkmark next to the answer.