I'm confused that:
CODE (CS01.cs)
The script is attached to a simple Cube object.
using UnityEngine;
using System.Collections;
public class CS01 : MonoBehaviour {
// Use this for initialization
void Start () {
Debug.Log (this); //--> Cube(CS01)
Debug.Log (this.GetType()); //--> CS01
Debug.Log (this.GetType() == typeof(UnityEngine.GameObject)); //--> False
Debug.Log (this == gameObject); //--> False
Debug.Log (this.name); //--> Cube
Debug.Log (gameObject.name); //--> Cube
this.name = "Hello"; // --> Will get the gameObject's name changed to 'Hello'
Debug.Log (gameObject.name); //--> Hello
}
// Update is called once per frame
void Update () {
}
}
1> Will CS01 be an script object right?
DOC: Scripting inside Unity consists of attaching custom script objects called behaviours to game objects.
2> In Component object, variables like transform, renderer, rigidbody are referenced to the components of gameObject this Component attached to. So in the script, this.renderer.material.color = Color.red; is equivalent to this.gameObject.renderer.material.color = Color.red. However, the description of variable name in the document name: The name of the object. only tells it's the name of the object.
3> So, how to understand the code above? Does the variable name also return the name of the gameObject this script attached to?
4> this means the script object but not the gameObject the script attached to, right?