- Home /
Unexpected Symbol `:' expecting :
Trying to create a simple cube object with my script based on this script reference.
Here's my code:
using UnityEngine;
using System.Collections;
public class rando : MonoBehaviour {
void Start () {
var cube : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = Vector3(0, 0, 0);
}
void Update () {
}
}
the error is at the var cube line(10) and it doesn't like the colon even though the script reference includes it. What am i doing wrong?
Answer by robhuhn · Sep 02, 2013 at 02:51 PM
There is a missing new. You copied the JS version but writing c#
... = new Vector3(0, 0, 0);
@edit
oh, and you have a js declaration for the cube. It should just be
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = new Vector3(0, 0, 0);
Answer by perchik · Sep 02, 2013 at 02:43 PM
Did you copy and paste that code into your script or type it from scratch? Sometimes when you copy and paste, bad symbols come in with the code.
If retype int doesn't work, try putting it on two lines:
var cube : GameObject;
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
tried that already. Still an error on the var cube : Gameobject line. I tried retyping the code as well.
Oh I didn't see that you were trying to write C#, I just saw it as JS
Your answer
Follow this Question
Related Questions
parser error? NpcDialog Script [pretty simple though...] 3 Answers
help please 2 Answers
Parser Error Unexpected symbol `m_MovementAudio' 1 Answer
Using JSON to get tree data into JavaScript objects 3 Answers
JSON Parse Errors: Get Line Numbers 0 Answers