zhaowei 8 лет назад
Родитель
Сommit
4a019df69e

BIN
Assets/Scenes/main.unity


+ 1 - 1
Assets/Script/ArrowLook.cs

@@ -11,7 +11,7 @@ public class ArrowLook : MonoBehaviour {
 	
 	// Update is called once per frame
 	void Update () {
-        transform.LookAt(GameObject.Find("cube").transform);
+      
     }
 
     public void Look(GameObject cube)

+ 1 - 1
Assets/Script/CameraFollow.cs

@@ -6,7 +6,7 @@ public class CameraFollow : MonoBehaviour
 {
 
     public Transform playerPos;
-    public float smooth = 1.5f;
+    public float smooth = 8;
 
     private Vector3 offsetPos;
 

+ 12 - 10
Assets/Script/GameGuide.cs

@@ -6,29 +6,31 @@ using UnityEngine.UI;
 public class GameGuide : MonoBehaviour
 {
     private string texts = "请根据箭头所指方向去收集能量块";
-    private float waitTime = 10f;
+    private float waitTime = 3f;
     private float timer = 0;
     private PlayerControl pc;
+
     public Text text;
-    public GameObject cube;
+    
     
 
     // Use this for initialization
     void Start()
     {
-        pc = GameObject.Find("player").GetComponent<PlayerControl>();
+        StartCoroutine(tip());
         
     }
 
     // Update is called once per frame
     void Update()
     {
-        timer += Time.deltaTime;
-        if (timer >= waitTime)
-        {
-            text.text = texts;
-            Instantiate(cube, new Vector3(3, 0, 3), Quaternion.identity);
-            timer = 0;
-        }
+        
+    }
+
+    IEnumerator tip()
+    {
+        yield return new WaitForSeconds(waitTime);
+        text.text = texts;
+        
     }
 }

+ 23 - 27
Assets/Script/PlayerControl.cs

@@ -4,12 +4,11 @@ using UnityEngine;
 
 public class PlayerControl : MonoBehaviour
 {
-    public GameObject arrow;
+    public float minSpeed = 0.7f;
+    public float maxSpeed = 1.4f;
 
-    Vector3 worldMousePos;
-    float dis = 0;
-    float player_speed = 0;
-    bool guide_one = false;
+    private float dis = 0;
+    private float player_speed = 0;
 
     // Use this for initialization
     void Start()
@@ -20,42 +19,39 @@ public class PlayerControl : MonoBehaviour
     // Update is called once per frame
     void Update()
     {
-        worldMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
-        dis = Vector2.Distance(new Vector2(transform.position.x, transform.position.z), new Vector2(worldMousePos.x, worldMousePos.z));
+        Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
+        mousePos.z = 0;
 
-        if (dis < 0.1f)
+        dis = Vector2.Distance(new Vector2(transform.position.x, transform.position.y), new Vector2(mousePos.x, mousePos.y));
+        if (dis <= 0.1f)
         {
 
         }
         else
         {
-            player_speed = dis * 1f;
-            player_speed = Mathf.Clamp(player_speed, 0, 1.3f);
-            TurnTo(worldMousePos);
-            transform.Translate(Vector3.forward * Time.deltaTime * player_speed);
-        }
-
-        
+            TurnTo(mousePos);
 
+            player_speed = dis * 0.5f;
+            player_speed = Mathf.Clamp(player_speed, minSpeed, maxSpeed);
+            transform.Translate(Vector3.up * Time.deltaTime * player_speed);
+        }
     }
 
-    void TurnTo(Vector3 offset)
+    void TurnTo(Vector3 pos)
     {
-        Vector3 dir = offset - transform.position;
-        dir.y = 0;
-        Quaternion q = Quaternion.LookRotation(dir);
-        transform.rotation = Quaternion.Lerp(transform.rotation, q, Time.deltaTime * 10f);
+        Vector3 dir = pos - transform.position;
+        float theta = Mathf.Atan2(dir.y, dir.x);
+        float angle = theta * Mathf.Rad2Deg;
+        transform.localEulerAngles = new Vector3(0, 0, angle - 90);
+
     }
 
-    void OnTriggerEnter(Collider other)
+    void OnTriggerEnter2D(Collider2D other)
     {
-        if (other.gameObject.name == "cube")
-        {
-            guide_one = true;
-            Destroy(other.gameObject);
-        }
+        Destroy(other.gameObject);
     }
 
-    
+
+
 
 }