The question is answered, right answer was accepted
What is the difference between vector2 and position?
Is vector2 simply a container with x and y coordinates, and is there a move function? vector2(10,10)
and why position is can not change x and y as directly? i get error by this position.x +=10 this is ok positon =new Vector2(10,10)
All variables have types. int Z; says Z is an int. It's like asking the difference between Z and int. "transform.position is a Vector2" is telling you it has an x or y. Also that Vector2 p = transform.position is legal.
transform,position.x+=1 is an error because of a bug in C#. position is a "property" which means your can't reach-through to change past it. Every language has weird "but why not?" stuff like that.
Answer by tormentoarmagedoom · May 06, 2019 at 11:34 AM
Hello @blendegg
Its simple,
Vector2 is a type of variable, like int, float, bool, string ...
Position is a value of a gameobject (Transform component of an object contains the position value, and rotation and scale)
Position in a 2D world, have 2 coordinates, so a VEctor2 variable is used to define the position. In a 3D world, position is represented as a Vector3 variable (X, y, Z)
Its like, a intensity of a light is represented with a int variable, or a name of an object is represented with a string type variable.
Bye!
?? light intensity can have a decimal point. It's a float.
Answer by Lightning_A · May 06, 2019 at 02:02 AM
I'm probably not the best person to answer this question since I'm also pretty new to Unity and C#, so if I'm wrong, I'm sorry, someone correct me. My understanding is that a Vector2 is essentially a variable that stores 2 values, and the position is a vector (I think it's actually a Vector3 which stores 3 values because Unity is a 3D program, though if you're making a 2D game the z axis isn't super important) that is automatically created for game objects in your scene. I don't think you can edit it using the position vector, I believe the position vector is just there for calculations. For movement functions I think you can use Transform.translate (or whatever other transformation you want to do), but I think the preferred way to do it is by applying forces with rigidbodies (which are used for physics). For a better answer I'd look up some tutorials on 2D player movement, I'm sure there's plenty of great ones.