- Home /
Design/discussion question
Instantiating multiple objects, Destroying and instantiating on trigger + delay
So what I'm trying to do is set up a semi large area with a "terrain" or plane made of cubes. The player is confined to movement along the X axis. I've got a simple script that instantiates a green cube prefab at the position of the gray cube on trigger, this works fine.
C#
using UnityEngine;
using System.Collections;
public class DestroyObjectReplace : MonoBehaviour {
public GameObject myPrefab;
void OnTriggerEnter (Collider collider) {
if (collider.gameObject.CompareTag ("Player")) {
Instantiate(myPrefab, transform.position, transform.rotation);
Destroy (this.gameObject);
}
}
}
Here's what I'm having trouble conceptualizing. The idea is that the world around the player changes as he advances through the world. I've used the same script as above to change the tree models, and I'll likely use it to change other models within the scene as I need them.
My current idea would be to create a plane made of hundreds of cubes, and as the player walks over the pavers, it would also trigger those to instantiate a new cube and destroy the old, but have a delay in each so it looks like a "wave" effect. I've uploaded a rough idea in gfy form: http://gfycat.com/WideGrandioseIndianspinyloach
So I've got the idea, but not the knowledge of how to implement that. I've been searching for a couple days now but I fear perhaps I'm not using the right keywords.
Any help is appreciated! Thank you :)
Design/discussion questions should be asked on Unity Forums. Unity Answers addresses single, specific technical questions. If you post there, consider including a link in this question so that anyone interesting in following or contributing to your question from this list can find the discussion.
I think your implementation will be too CPU intensive. Google 'Voxels' and '$$anonymous$$inecraft' on this list for alternates.