How can i let a sign appear when collected a certain amount of orbs ?
Script on the orbs
public int OrbAmmount;
public GameObject EnergyPickedUpFX;
void Start ()
{
}
void Update ()
{
}
void OnTriggerEnter2D(Collider2D Other)
{
if (Other.tag == "Player")
{
PlayerOrb TheOrb = Other.gameObject.GetComponent<PlayerOrb> ();
TheOrb.AddOrb (OrbAmmount);
Destroy (gameObject);
Instantiate (EnergyPickedUpFX, transform.position, transform.rotation);
}
}
}
Script for the sign
bool Activated = false;
public Transform WhereToSpawn;
public GameObject Sign;
private Orbs _Orbs;
public int AmmountToExit;
void Start ()
{
}
void Update ()
{
}
void CollectedAllOrbs()
{
if (_Orbs.OrbAmmount >= AmmountToExit)
{
Activated = true;
Instantiate (Sign, WhereToSpawn.position, Quaternion.identity);
Destroy (gameObject);
}
}
}
Hi, What issue are you getting? Do you need a sign in game? Don't you want to just activate a UI image? if count of orb higher than x then myUIItem.SetActive(true)?
i want a sign to appear when i have collected 35 orbs (for example). When i collect an orb it is counting in my UI ... so no problem there. The problem is this .... if (_Orbs.OrbAmmount >= AmmountToExit) I don't know what i am doing wrong. This if statement isnt working and i dont know why (i am new to coding).
BTW, this is the playerOrb script that i am talking about in the if statement in the orb script.
public int FullOrbs;
public int CurrentOrbs;
//HUD Variables
public Slider OrbSlider;
void Start ()
{
CurrentOrbs = 0;
//HUD Initialization
OrbSlider.maxValue = FullOrbs;
OrbSlider.value = CurrentOrbs;
}
public void AddOrb(int OrbAmmount)
{
CurrentOrbs += OrbAmmount;
if (CurrentOrbs > FullOrbs) CurrentOrbs = FullOrbs;
OrbSlider.value = CurrentOrbs;
}
}
Answer by Happy-Zomby · Apr 14, 2016 at 08:00 AM
Hi, Shouldn't you be comparing if (CurrentOrbs >= AmmountToExit)
rather than if (_Orbs.OrbAmmount >= AmmountToExit)
Personally I would move the sign instantiate to the playerOrb script And when you do AddOrb - put the if (CurrentOrbs >= AmmountToExit) there and if valid instantiate the sign
Answer by aadiboo95 · Apr 14, 2016 at 11:36 AM
Thank you verry my much!!!! Now it works perfectly :D
Your answer
Follow this Question
Related Questions
Word Space Text Appearing after Collecting the Object 1 Answer
how to end a level? 5 Answers
Level counter gets stuck on the first phrase. 2 Answers
How are those Resident evil/Silent hill type level transitions done? 1 Answer
Enter door? 1 Answer