i have been trying to make a game in unity, and i have tried to add a power up function to it, i tired using the yield return WaitForSeconds function but it wont work, here is the section of code that doesn’t work
}
}
IEnumerator Powerup(){
if (count4 == 1) {
speed = 20.5f;
powerText.text = "SPEED ORB";
yield return WaitForSeconds ("30");
speed = 10.5f;
count4 = 0;
powerText.text = "No Power Up";
}
}
}
when i go into the editor it gives the error of Expression denotes a type', where a
variable’, value' or
method group’ was expected
here is the full code just in case there is an error somewhere else;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;
public class StoryPlayer : MonoBehaviour {
public float cubes;
public Text countText;
public Text winText;
public Text powerText;
public Text lifeText;
public Text crewText;
public Text timer;
private Rigidbody rb;
private int count;
private int count2;
private int count3;
private int count4;
private int count5;
private float speed;
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 0;
count2 = 0;
count3 = 3;
count4 = 0;
count5 = 200;
speed = 10.5f;
SetCountText ();
SetCrewText ();
SetLifeText ();
winText.text = "";
powerText.text = "No Power Up";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pickup")) {
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
if (other.gameObject.CompareTag ( "Crew")){
other.gameObject.SetActive (false);
count2 = count2 + 1;
SetCrewText ();
}
if (other.gameObject.CompareTag ( "Foe")){
other.gameObject.SetActive (false);
count3 = count3 - 1;
SetLifeText ();
}
if (other.gameObject.CompareTag ("Speed")) {
count4 = 1;
StartCoroutine(Powerup ());
while (count5 >= 0)
other.gameObject.SetActive (false);
if (count5 == 0)
other.gameObject.SetActive (true);
}
}
void SetCountText ()
{
countText.text = "Cubes: " + count.ToString();
if (count >= cubes && count2 >= 1)
{
winText.text = "YOU WIN!";
Application.LoadLevel ("Chapter");
}
}
void SetCrewText()
{
crewText.text = "Crew: (" + count2.ToString () + "/1)";
}
void SetLifeText ()
{
lifeText.text = "Life: (" + count3.ToString () + "/3)";
if (count3 <= 0)
{
winText.text = "YOU LOSE";
Application.LoadLevel ("Chapter");
}
}
IEnumerator Powerup(){
if (count4 == 1) {
speed = 20.5f;
powerText.text = "SPEED ORB";
yield return WaitForSeconds ("30");
speed = 10.5f;
count4 = 0;
powerText.text = "No Power Up";
}
}
}
if any one can help me fix this or even suggest an alternate method it would be greatly apreaciated