1、打开unity3d选择菜单中的“GameObject”--“3D Object”。
2、在场景里面创建两个物体,一个Cube、一个Sphere。
3、接着我们创建两个脚本,一个Cube_data、一个Sphere_data。
4、把脚本分别对应放在两个物体上面。
5、在Sphere_data脚本中创建一个变量sphere_aa=100,作为要被获得的数据。
6、在Cube_data脚本的start中通过GameObject.Find获得并输出烂瘀佐栾这个sphere_aa变量的数值(旎髂坑若同样方式我们也可以获得其它组件属性)。void Start () { int aa =GameObject.Find("Sphere").GetComponent<Sphere_data>().sphere_aa; print(""+aa); }
7、运行游戏场景我们发现终端会输出变量的值100,Cube_data脚本获得Sphere物体上的数据成功。