- Home /
Better Random World generator c#
I created a c#-based random world generator through using this Script part:
...
public float RandomValue = 0;
void Start(){
RandomValue = Mathf.Round(Random.value);
if(RandomValue==1){
Destroy(gameObject);
}
...
This way the cubes are destroyed with a 50% chance. But there also cubes flying. So how can I check if theres another Cube under this?
Answer by siaran · Mar 15, 2015 at 08:52 PM
Well, you could just shoot a raycast down from your cube and see if it hits another cube? If you have different types of objects, check if it's a cube using a tag or a layermask or by checking if this script is on it, whatever is more convenient for you.
Or you could have just 1 script that has the position of all cubes stored in a convenient datastructure (position based tree maybe?) and use that to check & destroy cubes. (This option is imo better, but it's probably also slightly harder to implement).