unity-各种

两种旋转

transform.rotation = Quaternion.Euler (0, equral Time.deltaTimehor1, 0);
transform.Rotate (Vector3 (0, hor, 0) * eural * Time.deltaTime);

改变颜色

GameObject balloon;
void start(){
balloon = GameObject.Find ("Cube");
}
Bollon.GetComponent ().material.color = Color.red;
gameobject.GetComponent().material.color= Color.blue;
GetkeyDown是bool值

if (Input.GetKeyDown (KeyCode.Space)){}

设置父物体

transform.SetParent (mainCamera);
//获取父物体

// transform.parent;
//获取最上层父物体
// transform.root;
//脱离物体
transform.parent = null;

设置子物体.........getchild(0,1,2...);

//坐标系转换 本地坐标,世界坐标,屏幕坐标是像素点
// Camera.main.ScreenToWorldPoint (); //屏幕坐标转世界坐标
// Camera.main.WorldToScreenPoint(); //世界坐标转屏幕坐标
// Camera.main.ViewportToScreenPoint();//视口坐标转屏幕坐标
// Camera.main.ViewportToWorldPoint();//视口坐标转世界坐标

void OnMouseDown(){
//将物体的坐标转换为屏幕坐标
screenPoint=Camera.main.WorldToScreenPoint(transform.position);
//鼠标点击的位置和物体中心的偏移
offset=transform.position-Camera.main.ScreenToWorldPoint(
new Vector3(Input.mousePosition.x,Input.mousePosition.y,screenPoint.z));
}
void OnBeginDrag(){

}

//添加组件
gameObject.AddComponent();

[Serializable]//只能管紧跟着他的类 其他的管不了;
public class MyClass

鼠标控制镜头旋转

            vector 3是世界坐标      
            float a1 = Input.GetAxis ("Mouse X");
    float a2 = Input.GetAxis ("Mouse Y");
            要用四元素来转换一下
    transform.Rotate(0, a1 * anglue , 0,Space.World);
    transform.Rotate(a2 * anglue*-1, 0, 0,Space.Self);


         鼠标控制镜头围绕某一物体旋转

float a1;float a2; GameObject mainCamera;
if (Input.GetMouseButton (1)) {
print ("123");
a1 += Input.GetAxis ("Mouse X") * speed * Time.deltaTime;
a2 += Input.Getxis ("Mouse Y") * speed * Time.deltaTime*-1;
QuaternionA q = Quaternion.Euler (a2, a1, 0);
Vector3 direction = q * Vector3.forward;
transform.position = new Vector3(mainCube.transform.position.x,mainCube.transform.position.y,mainCube.transform.position.z) - direction * 10;
transform.LookAt (mainCube.transform);
}

找到一个物体的父物体
![K$N~D8(_QA2$LEQVRIS}EM.png

你可能感兴趣的:(unity-各种)