I’m asking myself the same question, and the answer is that I’m dumb, I have no idea why I used the this keyword there since it’s completely useless.
Since you asked, I’ll elaborate about the this keyword, which is particularly confusing when approaching it for the first time.
This refers to the instance of the object in which it’s used. So, you may ask, why should I use it if, in our example, transform.position and this.transform.position both reference to the same, exact thing? The answer is: you shouldn’t, unless the variable you’re trying to use is hidden by scope.
To explain what I mean by hidden by scope, let’s look at this example:
void Update (){
MoveWithStick(transform);
}
void MoveWithStick(Transform transform){
float h = Input.GetAxis("Horizontal") * shipSpeed * Time.deltaTime;
float v = Input.GetAxis("Vertical") * shipSpeed * Time.deltaTime;
transform.position += new Vector3 (h,v,0);
float newX = Mathf.Clamp (transform.position.x, xmin, xmax);
float newY = Mathf.Clamp (transform.position.y, ymin, ymax);
this.transform.position = new Vector3 (newX, newY, transform.position.z);
}
From Update(), I call MoveWithStick, but this time with a parameter of type Transform. Notice that I called the argument transform inside MoveWithStick on purpose - by using the same name I’ve hidden in the scope of the method the transform of the object, so that every time I use transform inside the method, I’ll change the local variable instead of the object transform.
And here’s where the keyword this becomes useful: if I want to access the variable hidden by the local one with the same name, I need to use the prefix this. in order to access the object’s transform, as I did in the last line of the code.
The 2nd way the this keyword is useful, is when you want to pass, when calling a method, the object itself from where you’re calling the method:
You can read about the this keyword here: https://msdn.microsoft.com/en-us/library/dk1507sz(VS.71).aspx - there’s a third reason when using this is useful, and it’s to do with indexers.
Regarding your second question, you should provide us with an example, since transform.position has both a getter and a setter, so you can modify its value, but only, of course, by passing a Vector3 (or Vector2) to it. If you’ve tried to change directly the x,y or z component of the position, then you get an error because those are read only.