Created
March 19, 2014 14:14
-
-
Save smallrice45/9642480 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Transform target; | |
float rotateSpeed = 10; | |
// Use this for initialization | |
void Start () { | |
// 將 target指定名稱為Imege的物件,並取得物件的Transform | |
target = GameObject.Find("Image").GetComponent<Transform>(); | |
} | |
void Update () { | |
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
RaycastHit hit; | |
Physics.Raycast(ray, out hit); | |
Debug.Log("This hit at " + hit.point ); | |
Vector3 pos; | |
pos = hit.point; | |
pos.z = 0; // 忽略z軸 | |
float angle = Vector3.Angle( pos - target.position, Vector3.down); | |
if(pos.x > target.position.x) { | |
angle*=-1; | |
} | |
target.rotation = Quaternion.Slerp(target.rotation,Quaternion.Euler(0,0,180-angle),rotateSpeed*Time.deltaTime); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment