C# 脚本

1. C#里使用Find函数查找物体时要用 GameObject:
GameObject.Find("Canvas/Text").GetComponent<Text>().text="Score";
2. 用Instantiate初始化物体时要用 as Transform 转换类型(对于 Transform 类型而言)
Transform Ball=Instantiate(newObject,transform.position,transform.rotation) as Transform;
3. Rigidbody.velocity是初速度、可以用Vector3赋值。
读取颜色要使用GetComponent<>():
OriginalColor=GetComponent<Renderer>().material.color;
用到Renderer的地方都要加GetComponent、这种情况还有很多…Audio→GetComponent<AudioSource>().…等、
19中老师讲的就是用Find系列函数会拖慢程序运行速度、可以在Start函数中用变量保存一下Find的结果、用到时调用这个变量:
Obj=GameObject.Find("Name");
Obj=GameObject.FindWithTag("TagName");
5. C#中结构体定义对象时要用new创建(不知是不是、不太确定)、比如 new Rect(…), new Vector3(…)等
6. 脚本命令使用方法:
[RequireComponent(typeof(CharacterController))]

posted @ 2016-06-30 12:42  CocomoNo1  阅读(444)  评论(0编辑  收藏  举报