Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 499
Procinogen Avatar asked Mar 02 '26 02:03

Procinogen


2 Answers

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);
like image 122
LVBen Avatar answered Mar 03 '26 14:03

LVBen


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.

like image 43
Chaos Monkey Avatar answered Mar 03 '26 15:03

Chaos Monkey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!