-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlantaController.cs
50 lines (39 loc) · 1.16 KB
/
PlantaController.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlantaController : MonoBehaviour
{
[Header("Componentes")]
private SpriteRenderer sprite;
private Animator PA;
[Header("Referências")]
public Transform planta;
public Transform player;
[Header("Configurações de Ataque")]
private float attackRange = 3f;
private bool isPlayerRange = false;
// Start is called before the first frame update
void Start()
{
sprite = planta.gameObject.GetComponent<SpriteRenderer>();
PA = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
float distancePlayer = Vector3.Distance(player.position, planta.position);
if(distancePlayer <= attackRange){
isPlayerRange = true;
}
else{
isPlayerRange = false;
}
if(isPlayerRange){
StartCoroutine(AttackCoroutine());
}
}
IEnumerator AttackCoroutine(){
PA.SetTrigger("Attack");
yield return new WaitForSeconds(1.0f);
}
}