summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/Scripts/VampireScript.cs
blob: 2f993d305615a20b253f819a8cf435a36a753dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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;

        }

    }

}