Hello guys, i’m struggling with something.
after my player loses all his lives, i want him to restart the level with a delay
i did add a yield but i keep getting an error i don’t know what to do
this is the error
Assets/Scripts/PlayerController.cs(56,14): error CS1624: The body of `PlayerController.SetCountText()' cannot be an iterator block because `void' is not an iterator interface type
and here is my script
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
public GUIText countText;
public GUIText winText;
public GUIText LiveText;
public GUIText LoseText;
public AudioClip LoseAudio;
public AudioClip LiveSound;
public AudioClip PickUpSound;
public AudioClip WinAudio;
private int PickUpCount;
public int LiveCount;
void start ()
{
PickUpCount = 0;
LiveCount = 3;
SetCountText ();
winText.text = "";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "PickUp")
{
AudioSource.PlayClipAtPoint(PickUpSound, new Vector3(5, 2, 2));
other.gameObject.SetActive(false);
PickUpCount = PickUpCount + 1;
SetCountText ();
}
if(other.gameObject.tag == "Obstacle")
{
AudioSource.PlayClipAtPoint(LiveSound, new Vector3(5, 2, 2));
other.gameObject.SetActive(false);
LiveCount = LiveCount - 1;
SetCountText ();
}
}
void SetCountText()
{
countText.text = "Blocks: " + PickUpCount.ToString ();
if (PickUpCount >= 16) {
AudioSource.PlayClipAtPoint (WinAudio, new Vector3 (5, 2, 2));
winText.text = ("WE MADE IT!");
}
{
LiveText.text = "Lives: " + LiveCount.ToString ();
if (LiveCount == 0) {
AudioSource.PlayClipAtPoint (LoseAudio, new Vector3 (5, 2, 2));
LoseText.text = ("TRY AGAIN BRO");
LiveCount = 0;
yield return new WaitForSeconds(5f);
Application.LoadLevel("level 2");
}
}
}
}
i’d love to get some help here