Instantiate

Hey all I have tried to spawn my cube for a while now I just used create.primitive to create the cube everytime the game is run on an empty spawn object. It clones the object in the hierarchy when I run the game but doesn’t show up when I run the game. Here i my code and a print screen if that helps.

using UnityEngine;
using System.Collections;

public class Spawner : MonoBehaviour{
   
    public GameObject Cube;
    public GameObject EmptyGameObject;
        public float spawnTimeDelay = 3f;
    public float spawnTimeInGame = 2f;
    public Vector3 spawnLocation = new Vector3 (0,2,0);
   
    void Spawner1 ()
    {
        Cube=GameObject.CreatePrimitive(PrimitiveType.Cube);
        Cube.transform.position = new Vector3(transform.position.x,transform.position.y,transform.position.z);
    }
   
    // Use this for initialization
    void Start  ()
    {
        InvokeRepeating ("Spawner1", spawnTimeDelay, spawnTimeInGame);
    }
}

Print Screen.

Is the issue that you are placing all of the cubes directly on top of one another? This would make a new one appear in the hierarchy, but it would not be visible in the game window as it is directly on top of another cube. Did you check that?

May I ask how I would check that? If you mean when I run the game like 20 Cube Clones pop up in the hierarchy.

Check in the inspector if those 20 Cubes are in the same x, y, z.

1 Like

What he said ^

Guys, I scripted all night and finally got the cubes to spawn. Problem is they are moving away from the player and are kinda going crooked.I had to change the color of the terrain to see the cubes.