/直接小写transform表示获取当前脚本所挂载的游戏对象身上的Transform组件

Vector3 p= transform.position;//     transform组件上的位置属性

//获取当前对象的位置存储到p中 当前对象是挂该脚本的对象

//transform.localPosition; 获取局部坐标系位置

print(p);

//获取当前游戏对象的rotation

//transform.rotation;旋转属性

//transform.localRotation;局部坐标系中的旋转属性

//rotation直接返回的数为四元数,而非vector3

//transform.localScale; 获取对象的缩放属性

//关于改变游戏的对象的transform属性

//transform.Translate(new Vector3(1,0,0));    改变

//改变当前游戏对象的位置

//transform.Rotate(Vector3.up, 10f);

//旋转当前游戏对象

//transform.eulerAngles = new Vector3(0f,10f,0f);

//使用欧拉角进行旋转,赋予一个状态,重复调用无法再次旋转

//关于获取对象的父对象与子对象的Transform属性

transform.parent; //获取对象的父对象的transform,能够更改

transform.root; //获取对象的根对象(最外层的父对象)的transform,不能更改

transform.Find("Cube");//通过参数来查找当前对象的子对象

//关于Time类

t = Time.time; //从游戏开始到当前帧所用的时间(秒)

dt = Time.deltaTime;//从上一帧到当前帧所用的时间

ts = Time.timeScale;//表示时间流逝的快慢,默认为1

//改为2表示时间加快为两倍,改为0表示时间停止,游戏暂停

transform.Rotate(Vector3.up, Time.deltaTime * 30f);//每秒钟转30度

//关于数学类Mathf

Mathf.Min();//求最小值

Mathf.Max();//求最大值

Mathf.Abs();//绝对值

Mathf.Sin();//求sin函数

Mathf.PI;//pi

Mathf.Sqrt();//求平方根

以下这段代码是在按下P键时能在场景中随机位置生成一个Prefab

  1. public class NewPrefab : MonoBehaviour {
  2. public GameObject prefab0;//通过公共字段获得一个预设体
  3. void Update () {
  4. if (Input.GetKeyDown("p"))
  5. {
  6. Vector3 pos = new Vector3();    /// 实例化一个对象 pos
  7. pos.y = 0.5f;
  8. pos.x = Random.Range(-5f, 5f);
  9. pos.z = Random.Range(-5f, 5f);
  10. Instantiate(prefab0,pos,Quaternion.identity);  //实例化
  11. //Quaternion.identity表示为空
  12. //也可以使用Quaternion.AngleAxis(,);来指定一个欧拉角
  13. //要获取到添加的游戏对象可使用以下方法:
  14. //GameObject p= Instantiate(prefab0,pos,Quaternion.identity) as GameObject;
  15. //使用Instantiate方法在场景中添加游戏对象,返回值类型为Object
  16. //使用as关键字将返回值转换为GameObject类型
  17. }
  18. }
  19. }

随机推荐

  1. Machine Learning and Data Science 教授大师

    http://www.cs.cmu.edu/~avrim/courses.html Foundations of Data Science Avrim Blum, www.cs.cornell.edu ...

  2. SQL Server系统数据库

    Master Master数据库保存有放在SQLSERVER实体上的所有数据库,它还是将引擎固定起来的粘合剂.由于如果不使用主数据库,SQLSERVER就不能启动,所以你必须要小心地管理好这个数据库. ...

  3. OpenJudge计算概论-扩号匹配问题【这个用到了栈的思想】

    /*====================================================================== 扩号匹配问题 总时间限制: 1000ms 内存限制: ...

  4. Oboe 提升web 用户体验以及性能

    Oboe  地址:http://oboejs.com/ 1.安装  bower bower  install oboe 2.使用,ajax 模式 oboe('/myapp/things.json') ...

  5. HTML5之Canvas绘图实例——饼状图

    实现饼状分布画图(如下):调试环境:Firefox

  6. eclipse svn subclipse下载地址

    http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240 Eclipse 3.x Subclipse release ...

  7. Ruby Regexp

    创建正则表达式对象 #以大写字母开始后面紧跟N个数字,方式一 reg = /[A-Z]\d+/ #方式二 reg = Regexp.new("[A-Z]\d+") reg = Re ...

  8. Eclipse换常用的快捷键

    还是喜欢ctrl+tab键来切换窗口,ctrl+f6实在不好使. 修改方法:在eclipse中Window -> Perferences -> General -> Keys -&g ...

  9. js替换字符指定字符方法

    1.递归替换 function replaceChar(str, oldChar, newChar) { if (str.indexOf(oldChar) != -1) { str = str.rep ...

  10. HackerRank "Manasa and Prime game"

    Intuitive one to learn about Grundy basic :) Now every pile becomes a game, so we need to use Spragu ...