Hello, i’m trying to do a simple thing, here’s the deal :
I enter the trigger zone of my base, i can upgrade it, up to 3 times, and each time i press the " interact " input in this trigger zone ( if i have enough resources ) , i upgrade the base ( i had 1 to the “level” variable ).
The problem is, if i have enough ressources to do multiple upgrades, it’ll skip to the highest upgrade i can have, even if i split the script with conditions. I don’t really know how to make the upgrade once in only one frame, and repeat the process, if i click again, etc…
Here’s the code:
void OnTriggerStay(Collider coll)
{
if (coll.CompareTag("Player"))
{
UIPlastic.text = "10";
UIVis.text = "10";
canvas.SetActive(true);
if (Input.GetButtonDown("Interact") && level == 0)
{
if (Inventaire.instance.totalPlastic >= 10 && Inventaire.instance.totalVis >= 10)
{
level = 1;
shield = 12.5f;
Inventaire.instance.SousVis(10);
Inventaire.instance.SousPlastic(10);
ScManager.runScore += 50;
}
else
{
CraftFail.text = "NOT ENOUGH RESOURCES !";
}
}
else if (Input.GetButtonDown("Interact") && level == 1)
{
if (Inventaire.instance.totalPlastic >= 10 && Inventaire.instance.totalVis >= 10)
{
level = 2;
shield = 25;
Inventaire.instance.SousVis(10);
Inventaire.instance.SousPlastic(10);
ScManager.runScore += 50;
}
else
{
CraftFail.text = "NOT ENOUGH RESOURCES !";
}
}
else if (Input.GetButtonDown("Interact") && level == 2)
{
if (Inventaire.instance.totalPlastic >= 10 && Inventaire.instance.totalVis >= 10)
{
shield = 50;
level = 3;
Inventaire.instance.SousVis(10);
Inventaire.instance.SousPlastic(10);
ScManager.runScore += 50;
}
else
{
CraftFail.text = "NOT ENOUGH RESOURCES !";
}
}
}
}
void OnTriggerExit(Collider coll)
{
if (coll.CompareTag("Player"))
{
CraftFail.text = "";
canvas.SetActive(false);
}
}
Hello.
You have multiple ways do get that.
First and most simple is to create a timer using Time.deltatime. Timer starts at 3 and goes down. Only when timer reaches 0 allows you to interact, and when interact, timer goes to 3 seconds again.
Another way is to change logic structiure to:
OnTrigerStay
if (Player)
if (Input.ButtonDown)
switch (ActualLevel)
case level 2
things;
case level 1
things;
case level 0
things;
So now, only 1 thing will be executed