|
@@ -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);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|