4

私は混乱しています:

コード (CS01.cs)

スクリプトは単純な Cube オブジェクトにアタッチされています。

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>CS01スクリプトオブジェクトになりますか?

DOC : Unity 内のスクリプティングは、動作と呼ばれるカスタム スクリプト オブジェクトをゲーム オブジェクトにアタッチすることで構成されます。

2>Componentオブジェクトでは、transform、renderer、rigidbody などの変数が、接続されているgameObjectthisのコンポーネントを参照しComponentます。したがって、スクリプトでthis.renderer.material.color = Color.red;は、は と同等this.gameObject.renderer.material.color = Color.redです。nameただし、ドキュメント内の変数の説明は、name: The name of the object.それがオブジェクトの名前であることを示しているだけです。
3> では、上記のコードを理解する方法は? 変数は、このスクリプトがアタッチされたゲームオブジェクトのnameも返しますか? 4>はスクリプト オブジェクトを意味しますが、スクリプトがアタッチされたゲーム オブジェクトではありませんよね?name
this

4

1 に答える 1