Ok guys I need some help , I coded the spawning script , but unity is saying that I need to assign the variable cube of spawner in the inspector. I did , but it still won’t work.
Posted this already.
Ok guys I need some help , I coded the spawning script , but unity is saying that I need to assign the variable cube of spawner in the inspector. I did , but it still won’t work.
Posted this already.
Check if the same script isnt attached to any other game object in the scene (which maybe dont have the cube attached).
Well it’s kinda complicated because I have spawnpoints I attached the code to. Is that the issue?
So when I attach the script to the spawnPoints that pops up.
Please I might ask for the code and a print-screen.
Code.
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour{
public GameObject Cube;
public float spawnTimeDelay = 3f;
public float spawnTimeInGame = 2f;
public Vector3 spawnLocation = new Vector3 (0,2,0);
void Spawn ()
{
GameObject SpawnLocation = (GameObject) Instantiate ( Cube, spawnLocation, Quaternion.identity);
}
// Use this for initialization
void Start ()
{
InvokeRepeating ("Spawn", spawnTimeDelay, spawnTimeInGame);
}
}
Also as you can see in the pic , I put the object to be spawned as cube, but it stilll won’t work.
Hello again.
Make your “Cube” a prefab! And then, assign the prefab on the “Cube” parameter.
And you can always give your code a warning for your self:
void Spawn ()
{
if (Cube) {
GameObject SpawnLocation = (GameObject) Instantiate ( Cube, spawnLocation, Quaternion.identity);
} else
Debug.LogWarning("Cube not assigned!");
}
I attached the cube prefab to the parameter , but it didnt work. Progress was made the cube now spawns when I run the game , only one cube though, and the cube just sits there and does nothing.Also the error is still present. Dang it.
Thanks though:)
Did you also attach the script to the other Spawnlocation object?
I decided to attach the cube prefab to the player, it shows up an supposedly spawns , but only one of the two spawn points spawn the object , the spawn cube doesn’t move or anything. It’s weird . I tried to put in the warning code PJ scripted , but unity gave me a bunch of errors. Good lord how hard is it to spawn something.