- Home /
Question by
watermelon69 · Feb 25, 2014 at 11:12 PM ·
spawnobjectsspawning problems
I need To spawn game objects randomly, but I'm Getting an error in My script, Please help!
Heres my script, Im a noob so i don't know how to fix my error. My error is CS0542 spawn.spawn()'; Member names cannot be the same as their enclosing type. -------------------
using UnityEngine; using System.Collections;
public class Spawn : MonoBehaviour {
public GameObject[] obj;
public float spawnMin = 1f;
public float spawnMax = 2f;
void Start () {
Spawn ();
}
void Spawn() <-----Error here
{
Instantiate(obj[Random.Range (0, obj.Length(0))], transform.position, Quaternion.identity);
Invoke ("Spawn", Random.Range (spawnMin, spawnMax));
}
}
Comment
Change the name of your script, or change the name of your function. They're BOTH named "Spawn".
Answer by flaviusxvii · Feb 25, 2014 at 11:14 PM
It's all in the error message, although some terms are sort of cryptic.
My error is CS0542 spawn.spawn()'; Member names cannot be the same as their enclosing type.
Basically you can't have a method called 'Spawn' in a class called 'Spawn'.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Spawn object problem 1 Answer
A node in a childnode? 1 Answer
Spawning Error.. 0 Answers
Movement Script Help 1 Answer