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?

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);

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);