Compile error "A new expression requires () or [] after type"

1

I'm creating a game based on a video on youtube ... And in this video has a link to the site with the codes, I copied the codes and pasted exactly as it was then to modify and do it my way ... But it's giving Unity errors that I can not solve!

The error occurs in the code of class Dinheiro :

using UnityEngine;
using System.Collections;

public class Dinheiro : MonoBehaviour {

public Vector2 velocity = new Vector2(0, -4);
public Vector3 velocity3D = new Vector3(0, -4, 0);
public float range = 4;

// Use this for initialization
void Start () {

    //rigidbody2D.velocity = velocity;
    transform.position = new Vector3(transform.position.x – range * Random.value, transform.position.y , transform.position.z);

}



// Update is called once per frame
void Update () {
    transform.position += velocity3D * Time.deltaTime;
}

}

The error message is A new expression requires () or [] after type and the compiler indicates line 14, where there is the command transform.position = new Vector3(... , as shown below:

    
asked by anonymous 27.02.2015 / 21:32

1 answer

2

After performing some tests, the problem appears to be related to the characters used in the code.

As you yourself said, you copied the code from a webpage and pasted directly into the Unity editor. Once the text has been pasted as formatted on the page (that is, using Unicode encoded characters instead of ANSI). For example, a longer hyphen rather than the minus sign is what caused the error pointed out in the question.

This type of error is more easily seen in strings where the pasted code is this (which are other errors you would get if you corrected that first):

InvokeRepeating(“CreateObstacle”, 1f, 1.5f); // em Generate.cs

instead of being this (using the normal ) as typed directly through the keyboard):

InvokeRepeating("CreateObstacle", 1f, 1.5f);

This "problem" probably stems from the Unity editor's characteristic of pasting formatted text (type RTF ). I do not know if this might or might not be considered a tool bug, but it probably causes these kind of difficulties frequently. :)

    
27.02.2015 / 22:21