常用核心类

 

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", "你好");
    }
  

相关文章

显卡天梯图2024最新版,显卡是电脑进行图形处理的重要设备,...
初始化电脑时出现问题怎么办,可以使用win系统的安装介质,连...
todesk远程开机怎么设置,两台电脑要在同一局域网内,然后需...
油猴谷歌插件怎么安装,可以通过谷歌应用商店进行安装,需要...
虚拟内存这个名词想必很多人都听说过,我们在使用电脑的时候...