shenhuan111 2015-04-18 07:30 采纳率: 64.3%
浏览 2992
已采纳

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条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器