I want to ask why we need to use the object ’ sphere’ to access (transform.position) which is (sphere.transform.position) in script1**,** but in script2, we can directly assess the (transform.Rotate) without any objects before it, I mean why not write the code in script2 like: sphere.transform.Rotate?
You may or may not be on the edge of a vast precipice known as programming. If whatever I write next doesn’t make sense to you, consider reading up on variable scopes in object-oriented programming.
First of all, transform.Rotate modifies the transform of the object that the script is attached to. So if Script 2 is attached to a Sphere it will rotate the Sphere, but if it is attached to a Banana, it will rotate the Banana. It is ambiguous which GameObject Script 2 is attached to.
When you need to act upon another object, that the script is not attached to, you use references. Variable sphere from Script 1 is a reference to a newly created Sphere, and Script 1 is not attached to it. If you write transform.position(without sphere) it will set the position of the object the script is attached to, instead of the created Sphere.
On the other hand, Script 2 has no awareness of variable sphere, which is in Script 1. Script 2 will not be able to figure out what is this sphere you are refering to if you write sphere.transform.Rotate.