C
C#5d ago
Ponge

Having issues with the [serializeField] thing

if someone can explain pls
No description
33 Replies
Angius
Angius5d ago
No description
Angius
Angius5d ago
Forgot a semicolon
Ponge
PongeOP5d ago
omg its just that thx so much damn while you are here can you help me with that error
Sehra
Sehra5d ago
one of the variables is likely a double so the rest is promoted to double as well, so Math.Sqrt returns a double and you are trying to assign it to a float
Ponge
PongeOP5d ago
it recommend to write (float) it seem it fixed it is it normal that i have to create a lot of serializeField for many things ?
Angius
Angius5d ago
In Unity? Yeah Anything you want exposed to the inspector has to be a SerializeField That said, if you don't want to expose something, no need for that attribute
Ponge
PongeOP5d ago
oh okay sorry last question
Ponge
PongeOP5d ago
No description
Ponge
PongeOP5d ago
No description
Ponge
PongeOP5d ago
why and thx so much for your past answer
Angius
Angius5d ago
The error is quite clear
Ponge
PongeOP5d ago
oh
Angius
Angius5d ago
rb.linearVelocity is a float You're trying to give it a Vector2
Ponge
PongeOP5d ago
ok so i erase vector2 ?
Angius
Angius5d ago
Square peg does not fit round hole
Ponge
PongeOP5d ago
ye but
Angius
Angius5d ago
Idk, do you?
Ponge
PongeOP5d ago
in tutorial video he does it ok i juste put = JumpForce it doesn't work he just goes in the air
Angius
Angius5d ago
You sure it's suppossed to be linearVelocityY and not, say, linearVelocity? Double-check with the tutorial
Ponge
PongeOP5d ago
actually it was linearVelocity.x now it says that :
Ponge
PongeOP5d ago
No description
Ponge
PongeOP5d ago
No description
Sehra
Sehra5d ago
could try removing Vector2 so it only says new(...)
Angius
Angius5d ago
Do you have a using System.Numerics reference? If so, remove it Would target-type new() work in Unity?
Ponge
PongeOP5d ago
ok i try
Sehra
Sehra5d ago
not sure which version unity use, probably something old
Angius
Angius5d ago
Standard 2.0 IIRC
Sehra
Sehra5d ago
seems like c# 7.3, so might not work
Ponge
PongeOP5d ago
i have the latest one
Ponge
PongeOP5d ago
No description
Ponge
PongeOP5d ago
with this he also goes in the air the tutorial seems old i try will try with a more recent one thx for everything
Buddy
Buddy5d ago
Don't follow tutorials blindly You will learn nothing from it Learn C# first then move to Unity when you feel ready

Did you find this page helpful?