Hello Again lovely community.
I am trying to spawn Blocks specifik Places randomly and for that i used random.range. However, It’s too fast so i wanted to yield it for x (in this case 5) seconds. But when i run this script i get this error message:
Assets/Scripts/MovementUP.cs(17,15): error CS1624: The body of MovementUP.respawm()' cannot be an iterator block because float’ is not an iterator interface type
So yeah that’s a thing.
Here’s the script. It’s a bit undone but as far as i know it doesn’t matter cause the problem is with the yielding (i am quite sure. Beats me which is why i am asking you Guys XD )
using UnityEngine;
using System.Collections;
public class MovementUP : MonoBehaviour {
new public GameObject Rocket;
new Vector3 StartPos = new Vector3 (0, -3, 0);
new Vector3 RightPos = new Vector3 (6,-3,0);
new Vector3 LeftPos = new Vector3 (-6,-3,0);
new public GameObject Block;
new Vector3 Middle = new Vector3 (0, 6, 0);
new Vector3 Right = new Vector3 (6, 6,0);
new Vector3 Left = new Vector3 (-6, 6,0);
new int i = 5;
float respawm()
{
int number = Random.Range (1, 3);
yield return new WaitForSeconds (5);
number = Random.Range (1, 3);
return number;
}
// Use this for initialization
void Start () {
Rocket.transform.position = StartPos;
}
// Update is called once per frame
void Update () {
if (random (1, 3) == 1) {
Instantiate (Block, Middle, new Quaternion(0, 0, 0, 0));
}
if (Input.GetKey (KeyCode.D)) {
Rocket.transform.position = RightPos;
} else if (Input.GetKey (KeyCode.A)) {
Rocket.transform.position = LeftPos;
}
else if ((Input.GetKey(KeyCode.A) == false ) & (Input.GetKey(KeyCode.D) == false))
{
Rocket.transform.position = new Vector3 (0,-3,0);
}
}
}