diff options
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts/VampireScript.cs')
-rw-r--r-- | WorldlineKeepers/Assets/Scripts/VampireScript.cs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/WorldlineKeepers/Assets/Scripts/VampireScript.cs b/WorldlineKeepers/Assets/Scripts/VampireScript.cs new file mode 100644 index 0000000..2f993d3 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/VampireScript.cs @@ -0,0 +1,68 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace MH +{ + + public class VampireScript : UnitBase + { + public Camera m_Camera; + + private SpriteRenderer m_Sprite; + + private bool m_Moving; + + void Start() + { + m_Moving = true; + m_Sprite = GetComponent<SpriteRenderer>(); + } + + protected override void Update() + { + base.Update(); + + if (Input.GetMouseButtonDown(1)) + { + m_Moving = !m_Moving; + } + + GetComponent<Animator>().speed = m_Moving ? 1 : 0; + + if (!m_Moving) + return; + + Vector3 mousePos = Input.mousePosition; + Vector3 mousePos3D = m_Camera.ScreenToWorldPoint(mousePos); + mousePos3D.z = 0; + + Vector3 pos = transform.position; + pos.z = 0; + + Vector3 toward = mousePos3D - pos; + toward.z = 0; + + if (toward.magnitude < 0.1f) + { + return; + } + + Vector3 dir = (mousePos3D - pos).normalized; + dir.z = 0; + + //pos.x += Time.deltaTime; + transform.position += dir * Time.deltaTime*2; + + Vector3 camPos = m_Camera.transform.position; + camPos.x = pos.x; + camPos.y = pos.y; + m_Camera.transform.position = camPos; + + m_Sprite.flipX = dir.x <= 0; + + } + + } + +} |