标签:
1
2
|
cube = GameObject.FindGameObjectWithTag(Tags.Cube).transform; cube1 = GameObject.FindGameObjectWithTag(Tags.Cube1).transform; cube2 = GameObject.FindGameObjectWithTag(Tags.Cube2).transform; |
1
2
3
|
//控制移动 float h = Input.GetAxis ( "Horizontal" ); float v = Input.GetAxis ( "Vertical" ); GetComponent<Rigidbody> ().MovePosition (transform.position - new Vector3 (h, 0, v) * speed * Time.deltaTime); |
1
2
3
4
5
6
7
|
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition); //控制转向,朝向鼠标 RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, 200, groundLayerIndex)) { Vector3 target = hitInfo.point; target.y = transform.position.y; transform.LookAt(target); } |
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
//鼠标左键点击围绕旋转 RaycastHit hit; if (Input.GetMouseButton (0)) { //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //RaycastHit hit; if (Physics.Raycast (ray, out hit)) { Debug.Log (hit.collider.name); //print("hello !"); //cube旋转 if (hit.collider.name == "Cube" ) { cube.Rotate (0, 1, 0); cube1.RotateAround (cube.position, new Vector3 (0, 5, 0), 60 * Time.deltaTime); cube2.RotateAround (cube.position, new Vector3 (0, 5, 0), 60 * Time.deltaTime); } if (hit.collider.name == "Cube1" ) { cube1.Rotate (0, 1, 0); cube.RotateAround (cube1.position, new Vector3 (0, 5, 0), 60 * Time.deltaTime); cube2.RotateAround (cube1.position, new Vector3 (0, 5, 0), 60 * Time.deltaTime); } if (hit.collider.name == "Cube2" ) { cube2.Rotate (0, 1, 0); cube1.RotateAround (cube2.position, new Vector3 (0, 5, 0), 60 * Time.deltaTime); cube.RotateAround (cube2.position, new Vector3 (0, 5, 0), 60 * Time.deltaTime); } } } |
标签:
原文地址:http://www.cnblogs.com/yushengqi/p/5670020.html