-
Notifications
You must be signed in to change notification settings - Fork 0
/
Avatar
66 lines (53 loc) · 1.25 KB
/
Avatar
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
using UnityEngine;
public class Avatar : MonoBehaviour
{
float speed = 0.9f;
public float delayHero = 4;
Transform tr;
Vector2 direction;
public bool isHero;
float sSpeed;
RaycastHit hit;
float maxRayDistance = 0.17f;
void Start()
{
tr = this.transform;
sSpeed = speed;
}
void Update()
{
Physics.Raycast(transform.position, direction, out hit, maxRayDistance);
if (hit.collider)
speed = 0;
else
speed = sSpeed;
Controls();
tr.Translate(direction * speed * Time.deltaTime);
if (isHero)
{
ResetHero();
}
}
void Controls()
{
if (Input.GetKey("down"))
direction = Vector2.down;
else if (Input.GetKey("up"))
direction = Vector2.up;
else if (Input.GetKey("right"))
direction = Vector2.right;
else if (Input.GetKey("left"))
direction = Vector2.left;
}
void ResetHero()
{
delayHero -= Time.deltaTime;
if (delayHero < 0)
isHero = false;
}
public void DeathEvents()
{
GameManager.instance.RespawnAvatarAfterDeath();
Destroy(gameObject);
}
}