- Home /
Node Respawn Script?
Sorta new to scripting (can read a script and understand it, but unsure of how to make one myself). I'm trying to write a script for nodes of minerals, such as Ore for mining in a game that you can gather from them.
I know I want to write something that would set the ore to be "alive" on awake, and then when it is gathered, or "killed", destroy it, then start a respawn timer, and then when the respawn timer hits 0, make it spawn that object to a certain point again.
I figure my variables would look something like this:
var respawnTimer : float = 10; var orePrefab : Transform; var spawnPoint : Transform; var oreDead : boolean = false;
.... Now, I'm not sure where to start, or what it would look like, or if I'm even missing some key variables... any tips?
What you want to make might be very clear in your head but it's very abstract for us (at least me) to understand what you want to do, what an ore node is represented by in your game and so on.
Could you tell us a little bit more about what you want to learn and how you picture the game part to look like? $$anonymous$$g. "There should be 3 icons on the screen. Each time I click one, my resource points for that resource should tick up by one. When I click a resource 5 times, that one should disappear for 10 seconds, sort of a cool down effect."
Not particularly sure what he means by nodes, but I believe all he wants to know is how to respawn his ore objects after a certain period of time following them having been destroyed. Am I correct @BaidBadger?
I would check out Invoke() for your respawn timer, as this will allow you to invoke a function after a certain period of time has elapsed. :)
Yes, you're correct actually... I was referring to the spent ore's original form as a "node" (Old WoW nerd ._.).
And that sounds wonderful... $$anonymous$$d dropping a link to a good reference?
Answer by Statement · Mar 10, 2013 at 04:48 AM
You could disable the collider of the ore node and hide the object until some time has expired.
You could do something like:
function OnOreDespawn() {
renderer.enabled = false;
collider.enabled = false;
Invoke("OnOreRespawn", 60); // Respawn in 1 minute
}
function OnOreRespawn() {
renderer.enabled = true;
collider.enabled = true;
}
But you'd need some code that calls OnOreDespawn after it has been "consumed".
Your answer
Follow this Question
Related Questions
Help! My respawn script isn't working! (Answered) 4 Answers
Respawn random objects 1 Answer
Why doesnt my checkpoint system work? 1 Answer
Respawn after falling off script? 2 Answers
Character respawns invisable? 1 Answer