- Home /
Pick up and Time delay problems
I tried to add a time delay to my code and make it wait a few seconds before moving onto the next level. But now with the new code, I am unable to pick up the object. Please help.
void Start ()
{
count = 0;
levelNumber = 1;
winText.text = "";
}
void OnTriggeEnter(Collider other)
{
if(other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive(false);
AddCount(1);
}
}
void AddCount(int val)
{
count += val;
countText.text = "Count: " + count.ToString();
if(count >= 1)
{
FinishLevel();
}
}
void FinishLevel()
{
levelNumber = levelNumber + 1;
winText.text = "CONGRAGULATIONS!";
Invoke("LoadNextLevel", 3);
}
void LoadNextLevel()
{
Debug.Log ("Level Number: " + levelNumber);
Application.LoadLevelAsync(Application.loadedLevel + 1);
}
}
Which object, what's picking up, what you mean by level?.. How can you expect a solution from us without giving any little information?
Are you sure the script is being used (can you try put in a breakpoint in OnTriggerEnter())?
Answer by superpentil · Jul 03, 2015 at 07:36 AM
I see a typo, so you may want to double check your code: OnTrigge*r*Enter(Collider other).
I'd also double check your tags and move AddCount(1);
before disabling other. It could be that when you disable it the trigger isn't 'triggered' anymore ending your function before you have a chance to call AddCount().
P.S. If you're loading another level after this pickup object is found, then instead of disabling it you can just Destroy() it. Though the memory difference will be minimal.
Thanks so much! It was just the typo, everything works fine now.
Your answer

Follow this Question
Related Questions
Destroy trigger after a certain time 2 Answers
How can I set a timer? 1 Answer
WaitForSeconds Not Working 1 Answer
Creating a small delay for a Pick up/drop script. 1 Answer
Delay before any action 3 Answers