码迷,mamicode.com
首页 > Windows程序 > 详细

4 c#

时间:2016-11-24 06:41:01      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:for   max   ide   transform   转换   update   orm   返回   comment   

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

4 c#

标签:for   max   ide   transform   转换   update   orm   返回   comment   

原文地址:http://www.cnblogs.com/wshyj/p/6095909.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!