Let me try to explain my issue,
for the purpose of this question, I have placed multiple prefabs of ‘grain sprouts’ in my scene of various heights.
Every 5 seconds I want to replace all the ‘sprouts’ objects with a larger grown plant and 5 seconds later with another prefab, till it is full grown at stage 4.
grain1 → 5 secs → grain2 → 5 secs → grain3 → 5 secs → grain4
This is what I have so far after days of searching and trying:
public class GrainGrow : MonoBehaviour {
private GameObject Grain1;
private GameObject Grain2;
private GameObject Grain3;
private GameObject Grain4;
private float time;
void Start() {
Grain1 = GameObject.FindGameObjectWithTag("Grain1");
Grain2 = GameObject.FindGameObjectWithTag("Grain2");
Grain3 = GameObject.FindGameObjectWithTag("Grain3");
Grain4 = GameObject.FindGameObjectWithTag("Grain4");
time = 0;
}
void Update ()
{
time += Time.deltaTime;
if (time >= 5) {
grow();
}
}
void grow(){
Instantiate(Grain4, Grain3.transform.position, Grain3.transform.rotation);
Instantiate(Grain3, Grain2.transform.position, Grain2.transform.rotation);
Instantiate(Grain2, Grain1.transform.position, Grain1.transform.rotation);
time = 0;
}
}
- This will transform my last placed object to a higher level but not the others on the same level.
- 10 seconds after start, the new objects won’t grow anymore.
note1: I dont just want to change the size of the object but replace it with a new one.
note2: I probably want to change the ‘grow-time-interval’ to a month, so when a new spout is planted 1 week later, it has to grow 1 week later as well.
I hope anyone can help me in the right direction with this. I am new to unity and c#. I am eager to learn but sometimes it is hard to find the right answer in the www-jungle