1.针旋转
GameObject a(针) Vector3 b(欧拉角)
~b=Camera.main.transform.eulerAngles;
~float c = b.y;
~Quaternion Qua = Quaternior.Euler((float)0,(float)0,c);
~a.transform.rotation = Qua;
2.游戏暂停开始
Time.timeScale = 0;暂停
Time.timeScale = 1;开始
注意:游戏暂停,但是动画不停(飞机头转动的时候(.time.deltaTime))
3.两个对象之间连线
(对象a,对象b)
用控件Line Renderer
private LineRenderer line;
private Transform c;
line = GetComponent<LineRenderer>();
line.SetPosition(0,transform.position);
if (c!=null)
{
line.SetPosition(1,c.position);
}
4.摄像机拖拽(平移,旋转)(right–x轴,up–y轴,forward–z轴)
float _offset = Input.GetAxis("Mouse ScrollWheel");
transform.Translate(Vector3.forward * 70 * _offset, Space.Self);
if (Input.GetMouseButton(1))
{//旋转
float _offsetx = Input.GetAxis("Mouse X");
float _offsety = Input.GetAxis("Mouse Y");
transform.Rotate(Vector3.up, _offsetx * 70);
transform.Rotate(Vector3.right, _offsety * 70);
//保证旋转的时候z轴不转
Vector3 _eular = transform.eulerAngles;
Quaternion qua = Quaternion.Euler(_eular.x, _eular.y, (float)0);
this.transform.rotation = qua;
}
if (Input.GetMouseButton(2))
{//平移
float _offsetx = Input.GetAxis("Mouse X");
float _offsety = Input.GetAxis("Mouse Y");
transform.Translate(Vector3.up*70*_offsetx*-1,Space.Self);
transform.Translate(Vector3.up * 70 * _offsety * -1, Space.Self);
}
5.调用其它脚本的函数
i被调用的脚本函数为static类型 脚本名.函数名()
ii GameObject.Find(“脚本所在物体名”).SendMessage(“函数名”);
iii GameObject.Find(“脚本所在物体名”).GetComponent<脚本名>().函数名();—–只能调用Public类型的函数
6.截取小数点后2位 ToString(“f2”);
7.获取系统时间
DateTime.Now.ToLocalTime().Hour
DateTime.Now.ToLocalTime().Minute
8组合键
ctrl + A为例
if (Input.GetKey(KeyCode.LeftControl))
{
if (Input.GetKeyDown(KeyCode.A))
{
}
}
9全屏显示
退出全屏 Screen.fullScreen = false;
全屏显示 Screen.SetResolution(1920,1080,true);
10.禁用脚本
点一下禁用,点两下启用
a.enabled = !a.enabled;
点一下消失,点两下显示
a.SetActive(!a.activeSelf);