I'm working on a small game, where the player has to find their home. Ideally the house would spawn at a new location every time the game is played. I am new to coding so I'm not sure if what I have made works/ make sense. So far I added a condition to check if the house(right now just a cube) is in the game. However I have no idea if it is working. Without the condition the cube does keep spawning. I am also having trouble spawning the cube in a different location each time. It shows up in the same spot no matter what.
![alt text][1]
This is what happens without the condition.
[1]: /storage/temp/200147-my-pink-world-prototype-pc-mac-linux-standalone-un.png
**Code below:**
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RandomPlacement : MonoBehaviour
{
public GameObject cubePrefab;
void Update()
{
if (cubePrefab ==true) {
Spawn();
}
void Spawn()
{
Vector3 randomSpawnPosition = new Vector3(Random.Range(0, 11), 50, Random.Range(0, 11));
Instantiate(cubePrefab, randomSpawnPosition, Quaternion.identity);
}
}
}
Trending Articles
More Pages to Explore .....