unity常用核心类
1.Transform
a.移动:1.属性:transform.position = new Vector3(2, 0,0);//放在Update固定值
transform.position = Vector3.right * 2;//放在Update固定值
2.方法:transform.Translate(new Vector3(2, 0, 0));//放在Update一直循环
transform.Translate(Vector3.right * 2);//放在Update一直循环
transform.Translate(2, 0, 0);//放在Update一直循环
b.旋转:1.属性:transform.rotation = Quaternion.Euler(0, 45, 0);//放在Update固定值
2.方法: transform.Rotate(new Vector3(0, 45, 0));//放在Update一直循环
c.缩放(只有属性):1.属性:transform.localPosition = new Vector3(2, 2, 2);//放在Update固定值
transform.localScale = Vector3.one * 2;//放在Update固定值
2.Vector3
a. public GameObject B1;//GameObjeect游戏对象 gameObject脚本对象
public GameObject B2;
void Start () {
transform.position = B1.position + B2.position;
gameObject.transform.position = B1.transform.position + B2.transform.position;
}
b.public Transform a;
public Transform b;
public Transform c;
void Update ()
{
b.position = new Vector3(5, 0, 0);
c.position = new Vector3(-5, 0, 0);
a.position = b.position + c.position;
}
3.GameObject
b.脚本在摄像机上面挂载
public GameObject cube;
void Update ()
{