Hey there, I’m an absolute noob, when it comes to programming but I need to learn it to program a simple game for my Bachelor Thesis.
What I’m trying to do, is letting an object spawn in a set interval and letting it disappear shortly after each spawn.
What happens instead, is that after the time that is set by the Despawntimer, the object just stops spawning and those that already did don’t disappear.
I’d tried it with the following code:
{
public GameObject HilfeSchriftzug;
public int Hilfes = 2;
public float timer = 0;
public float Despawntimer;
void Start()
{
}
void Update()
{
timer = timer + Time.deltaTime;
if (timer < Hilfes)
{
}
else
{
Instantiate(HilfeSchriftzug, transform.position, Quaternion.identity);
timer = 0;
Destroy(HilfeSchriftzug, Despawntimer);
}
}
}
Would be awesome if somebody could help me with this issue ![]()
Thank you very much, that helped a lot! :) Just a quick follow up question: What exactly is the function of "this"? Haven't seen it yet and tried the code without it and it worked anyway.
– corniking"this" is a keyword, it's a reference on the current class, I got used to use it to discern local variable from class variable and same with function, but it's just a habit it doesn't change anything to the code or the logic
– Cyber_CatsAlright, good to know. Thanks again!
– corniking