常用核心类

 

Transform和Vector3:

         //位移
        //transform.position = new Vector3(10, 0, 0);//向右移动10米
        //transform.localPosition = new Vector3(10, 0, 0);//相对于父类物体向右移动10米

        //transform.Translate(new Vector3(10, 0, 0),Space.World);
        //transform.Translate(new Vector3(10, 0, 0), Space.Self) ;

        //transform.Translate(new Vector3(10, 0, 0));//默认是世界坐标

        //print(transform.position);
        //print(transform.localPosition );

        //归零
        //transform.position = new Vector3(0, 0, 0);
        //transform.localPosition = new Vector3(0, 0, 0);

        //旋转
        //transform.rotation = Quaternion.Euler(0, 45, 0);
        //transform.localRotation  = Quaternion.Euler(0, 45, 0);

        //transform.Rotate(new Vector3(0, 45, 0), Space.World);
        //transform.Rotate(new Vector3(0, 45, 0));

        //transform.Rotate(new Vector3(0, 45, 0), Space.Self );

        //缩放
        transform.localScale = new Vector3(2, 1, 1);

Time:

时间类

克隆:

GameObject go2 =Instantiate(cube,new Vector3(0,0,5),Quaternion.identity);

销毁游戏对象

Destroy(go1);    //直接销毁对象go1

Destroy(go2,3);   //3秒后销毁对象go2

查找游戏对象

通过游戏对象名称来查找游戏对象

GameObject  cube=GameObject.Find("Player");

鼠标事件

GetMouseButton(0):按下鼠标左键不动,程序会一直运行,松开左键程序停止运行。

GetMouseButton(2):按下鼠标中键不动,程序会一直运行,松开中键程序停止运行。

GetMouseButton(1):按下鼠标右键不动,程序会一直运行,松开右键程序停止运行。

GetMouseButtonDown(0):按下鼠标左键时,程序运行一次

GetMouseButtonDown(1):按下鼠标右键时,程序运行一次

GetMouseButtonUp(2):按下鼠标中键时,程序不运行,松开中键时,程序运行一次。

键盘事件

if(Input.GetKey(KeyCode.A)){

   print(“按着A键”);

}

if(Input.GetKeyDown(KeyCode.A)){

   print(“按下A键”);

}

if(Input.GetKeyDown(KeyCode.UpArrow)){

   print(“按下上键”);

}

协程

void Start ()

{

StartCoroutine(Print);

}

IEnumerator Print ()

{

yield return new  WaitForSeconds(3f);

print("你好")

}

信息发送:

 public void Scale(int a)
    {
        transform.localScale = transform.localScale * a;
    }

void Update () {
        if (Input.GetKeyDown (KeyCode.Escape))        
        {
            BroadcastMessage("Scale", 2);
        }

 //向自己发送信息
        //SendMessage("GetMessage", gameObject, SendMessageOptions.RequireReceiver);
        //向父级发送信息
        //SendMessageUpwards("Two","hello",SendMessageOptions.DontRequireReceiver );
        //SendMessageUpwards("Two", "hello", SendMessageOptions.RequireReceiver);
        //向子级发送信息
        //BroadcastMessage("Two", "你好");
    }
  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值