Het
Het

Reputation: 203

Expression denotes a `type', where a `variable', `value' or `method group' was expected UNITY3D

void Update () {
      float xP = Input.GetAxis ("Horizontal")*Time.deltaTime * 20; 
      transform.Translate (Vector3(xP,0,0));//error is here 
      transform.position.x = Mathf.Clamp (transform.position.x, -10, 10);
} 

error : Expression denotes a type', where avariable', value' ormethod group' was expected`

Upvotes: 1

Views: 5888

Answers (1)

Tim S.
Tim S.

Reputation: 56576

You're missing the new keyword that's necessary to call a constructor from C# code. Maybe the code was improperly translated from another language (e.g. the syntax there is valid in Python/Boo), or just written incorrectly.

transform.Translate(new Vector3(xP, 0, 0));

You should consider writing it with Vector3.right instead, to clarify the direction:

transform.Translate(Vector3.right * xP);

Upvotes: 3

Related Questions