I have a problem with this spawning script and I don’t know how to repair it.
using UnityEngine;
using System.Collections;
public class Spawn : MonoBehaviour {
public GameObject[ ] eggs;
private float time;
public float timelimit=0.5f;
bool spot=false;
void Start () {
}
void Update () {
time += Time.deltaTime;
if (time >= timelimit) {
time = 0;
StartCoroutine(Spwn());
}
}
public void Spot(bool x)
{
spot = x;
}
IEnumerator Spwn()
{
while(!spot)
{
spot=true;
Instantiate(Random.Range(0f,11f), new Vector3(Random.Range (-37.31105f,51.35894f), 0f,Random.Range (-115.5185f,-189.02f)), Quaternion.identity) as GameObject;
yield return null;
}
}
}
use the Code Tags
Also you should explain what your problem is and post any error messages that unity gives you in the console.
using UnityEngine;
using System.Collections;
public class Spawn : MonoBehaviour {
public GameObject[] eggs;
private float time;
public float timelimit=0.5f;
bool spot=false;
void Start () {
}
void Update () {
time += Time.deltaTime;
if (time >= timelimit) {
time = 0;
StartCoroutine(Spwn());
}
}
public void Spot(bool x)
{
spot = x;
}
IEnumerator Spwn()
{
while(!spot)
{
spot=true;
Instantiate(Random.Range(0f,11f), new Vector3(Random.Range (-37.31105f,51.35894f), 0f,Random.Range (-115.5185f,-189.02f)), Quaternion.identity) as GameObject;
yield return null;
}
}
}
Sorry for the post, i didn’t know about the code tag and the error is: Assets/Spawn.cs(31,182): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement, at the 31st line
You are trying to Instantiate a float value… should be a gameobject
Instantiate(prefabName, newVector3(Random.Range(-37.31105f,51.35894f), 0f,Random.Range(-115.5185f,-189.02f)), Quaternion.identity)asGameObject;