返回的类会影响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");
}
}
对于引用类型,是对象的引用(你可以理解为是指针)
对于值类型(struct),是值。
对于引用类型,是对象的引用(你可以理解为是指针)
对于引用类型(struct),是值。
返回这了类实例,或是它的引用,修改会影响源对象
c#中类是引用类型,getcomponet<>()获取的是类的引用,会对原有类造成影响.