-
Notifications
You must be signed in to change notification settings - Fork 1
/
Interacao.cs
104 lines (94 loc) · 2.79 KB
/
Interacao.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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Interacao : MonoBehaviour,Interable
{
[SerializeField]
private Image barra;
private int LootQtd;
public bool Used = false;
public GameObject[] Coletaveis;
public bool isLootBox = false;
public bool isBase = false;
private Animator animator;
public GameObject Player;
public GameController gameController;
private Coroutine start;
[SerializeField]
private Canvas canvas;
public void Start()
{
if(!isBase){
canvas.enabled =false;
}
barra.fillAmount = 0;
}
public virtual void Interact()
{
if(!isBase && !Used){
canvas.enabled = true;
start = StartCoroutine(Progresso());
}else{
startTowerDefense();
}
}
public virtual void StopInteract()
{
if(start!= null)
{
StopCoroutine(start);
start = null;
canvas.enabled = false;
}
}
private IEnumerator Progresso(){
float timeleft = Time.deltaTime;
float rate = 1.0f/5.0f;
float progress = 0.0f;
while(progress <1.0)
{
barra.fillAmount = progress;
progress += rate*Time.deltaTime;
yield return null;
}
if(barra.fillAmount > 0.90){
animator = GetComponent<Animator>();
if(!Used){
print("TA INTERAGINDO");
LootQtd = Random.Range(3,6);
if(isLootBox){
animator.SetBool("Open",true);
gerarLoot();
}
if(isBase){
print("TA NA BASE");
startTowerDefense();
}
Used = true;
canvas.enabled =false;
}
// Destroy(gameObject);
}
}
void gerarLoot(){
for(int x = 0; x < LootQtd;x++){
int randomItem = Random.Range(0,Coletaveis.Length);
Instantiate(Coletaveis[randomItem],new Vector2(transform.position.x+Random.Range(0,2),transform.position.y+Random.Range(0,2)),Quaternion.identity);
}
}
void startTowerDefense(){
if(gameController.Status != "DIA"){
Player.GetComponent<SpriteRenderer>().enabled = false;
Player.GetComponent<BoxCollider2D>().enabled = false;
gameController.Status = "NOITE";
gameController.horasCont = 19;
print("PODE ENTRAR");
}else{
print("INDISPONIVEL");
}
}
// public float OpenChest()
// {
// }
}