base spawning portal

There’s a game object, which instantiates a prefab (enemy) in random time range (1-5)
it always shows me an error (sometimes two) like “phrasing error” and “Expecting ;”
Help me please

using UnityEngine;
using System.Collections;
var prefab : GameObject;
public class Spawner : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () 
			{
			Instantiate (GameObject);
			yield WaitForSeconds (Random.Range(1,5));
			}
}

Two problems are immediately visible…

You don’t declare variables with “var” when using C#, you just use the type name followed by the variable name. Also, the variable needs to be declared inside the class, so you would have:-

public class Spawner : MonoBehaviour {
    GameObject prefab;
    ...

The second problem is that you don’t use just “yield” in C#, you use “yield return”. Check out the manual page on the differences with C# for more information.

Thanks, it helped

now my code is like this

using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour {
public GameObject objEnemy;
	
   // Use this for initialization
   void Start () {
   objEnemy = (GameObject) GameObject.FindWithTag ("Enemy");
   }
   
   // Update is called once per frame
   void Update ()
   {
	   SpawnPoint();
   }
   
   void SpawnPoint ()
         {
         Instantiate (Enemy);
         yield return WaitForSeconds (Random.Range(1,5));
         }
}

but it shows me

Sorry, i’m a real noob =0|

or this one

using UnityEngine;
using System.Collections;

public class Spawner : MonoBehaviour {
//var GameObject enemyPrefab
	public GameObject objEnemy;
	
   // Use this for initialization
   void Start () {
	
      }
   
   // Update is called once per frame
   void Update ()
   {
	  objEnemy = Instantiate(objEnemy);
	  yeld return 0;
   }
   
}

and it shows me

the trouble is the same: what’s the problem O_o
And how must it be?[/quote]

[/quote]
On Update you missing i on word yield. Compiler think you want declare yeld and forgot ;[/b]

yield return WaitForSeconds (Random.Range(1,5));

this should be in method which return value is IEnumerator :smile:.

IEnumerator SpawnPoint ()
         {
         Instantiate (Enemy);
         yield return new WaitForSeconds (Random.Range(1,5));
         }

This error quite clearly states that. `void’ is not an iterator interface type, IEnumerator is.

Assets/Scripts/Spawner.cs(17,9): error CS1624: The body of Spawner.SpawnPoint()' cannot be an iterator block because void’ is not an iterator interface type