1
I’m creating a video game based on a youtube... And in this video there is a link to the site with the codes, I copied the codes and pasted it exactly as it was to later modify and do my way... But there are some mistakes in Unity that I can’t fix!
Error occurs in class code 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:
Apparently there’s nothing wrong with line 14 of the class
Dinheiro
(with the commandtransform.position = new Vector3...
). Are you sure that this is the code being used by your Unity project?– Luiz Vieira
Yes, I’m sure! I’ve seen nothing wrong, I’ve wondered too!
– Flávio Ricardo
Okay. If you zip up your project and put it somewhere for me to download, I can try it out here on my Unity. Ah, and next time you open a question try to be more objective and complete. You could have just put the class code
Dinheiro
, indicated the line where potentially the problem is (because the compiler tells you so). Also avoid loose headings (like the one you used). So you probably wouldn’t have received the negative votes you received. :)– Luiz Vieira
Okay, thank you so much for the tips! I put it in Dropbox: https://www.dropbox.com/s/h93lj2j700t74ui/Unity2D.zip?dl=0
– Flávio Ricardo