unity3D 点击地图人物移动的方向问题

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class MapTest : MonoBehaviour 
 5 {
 6 
 7     public GameObject palyer;
 8     Animation anim;
 9     // Use this for initialization
10     void Start () 
11     {
12         
13     }
14     
15     // Update is called once per frame
16     void palyerMove() 
17     {
18         anim = palyer.GetComponent<Animation>();
19         anim.Play("n_idle");
20         anim.wrapMode = WrapMode.Loop;
21     }
22     void Update () 
23     {
24 
25         if (Input.GetMouseButtonUp(0))
26         {
27             
28             Ray ray = gameObject.camera.ScreenPointToRay(Input.mousePosition);//Input.GetTouch(0).position
29             RaycastHit hit;
30             Debug.Log("1:"+Input.mousePosition);
31          //   Vector3 pos = hit.transform.position;
32             if (Physics.Raycast(ray, out hit))
33             {
34                 
35                 GameObject map = hit.collider.gameObject;
36                 Debug.Log(map.name);
37                 if (map.name == "00000")
38                 {
39                     anim = palyer.GetComponent<Animation>();
40                     anim.Play("n_run");
41                     anim.wrapMode = WrapMode.Loop;
42                     Debug.Log("2:" + hit.point);
43                     Vector3 pos = hit.point;
44                     Vector3 relativePos = pos - palyer.transform.position;
45                     Quaternion rotation = Quaternion.LookRotation(relativePos);
46                     //Quaternion rotat = Quaternion.LookRotation(hit.point-transform)
47                   //  palyer.transform.rotation = rotation;
48                     palyer.transform.localEulerAngles = new Vector3(0, rotation.eulerAngles.y, 0);
49                    // Vector3 pos = Input.mousePosition;
50                     iTween.MoveTo(palyer, iTween.Hash("position", new Vector3(pos.x, 0, pos.z), "time", 1, "easetype", "linear", "oncomplete", "palyerMove", "onCompleteTarget", gameObject));
51                 }
52 
53             }
54         }
55     }
56 }

 

posted @ 2014-02-17 17:45  kadajEvo  阅读(233)  评论(0)    收藏  举报