Newer
Older
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
69
70
71
72
73
74
75
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovementController : MonoBehaviour
{
private Rigidbody2D rb;
private string horizontalAxis;
private string verticalAxis;
[SerializeField] private float speed;
private Animator animatorController;
private float timePassed;
private bool canMove;
private bool canShoot;
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody2D>();
animatorController = GetComponent<Animator>();
horizontalAxis = "Horizontal";
verticalAxis = "Vertical";
timePassed = 0;
canMove = true;
animatorController.SetBool("Moving", false);
animatorController.SetBool("Shooting", false);
animatorController.SetTrigger("AtkTurn");
}
private void Update()
{
if (rb.velocity == Vector2.zero)
{
animatorController.SetBool("Moving", false);
}
else
{
animatorController.SetBool("Moving", true);
}
}
// Update is called once per frame
private void FixedUpdate()
{
if (Input.GetKeyDown(KeyCode.Z))
{
StopCoroutine("move");
StartCoroutine("skill");
}
else if (canMove)
{
StartCoroutine("move");
}
}
private IEnumerator move()
{
rb.velocity = new Vector2(Input.GetAxisRaw(horizontalAxis), Input.GetAxisRaw(verticalAxis)) * speed;
transform.rotation = rb.velocity.x <= 0 ? Quaternion.AngleAxis(180, Vector3.up) : Quaternion.AngleAxis(0, Vector3.up);
yield return null;
}
private IEnumerator skill()
{
canMove = false;
while (timePassed < 1)
{
rb.velocity = new Vector2(1, 1) * speed;
timePassed += Time.deltaTime;
yield return null;
}
timePassed = 0;
canMove = true;
}
}