shenhuan111 2015-04-18 07:30 采纳率: 0%
浏览 2994
已采纳

C#中GetComponent<T>(),如果T是一个类的话,返回的是类的地址吗,还是一个类

返回的类会影响T本事内容吗??
官网查的:
Object GetComponent (
PropertyDescriptor propertyDescriptor
)
B类中的a.i会改变A中的类的i的值,可是这个 GetComponent 不是一个地址形式,为什么会改变呢??

 using UnityEngine;
using System.Collections;

public class B : MonoBehaviour {
    A a;
    A a1=new A();
    // Use this for initialization
    void Start () {
        a = GetComponent<A>();
    }

    // Update is called once per frame
    void Update () {
        if (Input.GetKey(KeyCode.A))
        {
            a1.i = 4;
        }

}

using UnityEngine;
using System.Collections;

public class A : MonoBehaviour {
    public int i;
    // Use this for initialization
    void Start () {
        i = 3;
    }

    // Update is called once per frame
    void Update () {
        if (i == 4)
            print("i=4 \n");
    }
}

  • 写回答

4条回答 默认 最新

  • threenewbee 2015-04-18 07:36
    关注

    对于引用类型,是对象的引用(你可以理解为是指针)
    对于值类型(struct),是值。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?