Procinogen
Procinogen

Reputation: 59

How do I use a negative number?

I was working on a little project in the Unity game engine. I was doing something with transform.position, until I ran into a problem. I needed to use a negative number for the z coordinates, but whenever I use a negative number,

I the following error: error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

So I lead to the conclusion that there was a problem with a negative number. I couldn't find anything related to this, so I decided to ask a question. Here is part of my code:

transform.position = Vector3(32.23805f, 0.4999998f, -17.32514f);

Upvotes: 3

Views: 1028

Answers (2)

Chaos Monkey
Chaos Monkey

Reputation: 984

when not using the new keyword, the compiler would assume that you are trying to declare a type of a variable instead of assigning a value to the trasform.position variable. that is why you are getting the error

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

just add the new keyword and it should work.

Upvotes: 1

LVBen
LVBen

Reputation: 2061

This isn't a problem with using negative values. You are missing the "new" keyword.

Try this:

transform.position = new Vector3(32.23805f, 0.4999998f, -17.32514f);

Upvotes: 9

Related Questions