Hi, It’s since a week that I’ve this problem, in IEnumerator function, i get the error “Unexpected symbol”. I really hope that someone can Help me! 
using System;
using UnityEngine;
public class LightAnimator : MonoBehaviour {
Coroutine lightOnCoroutine;
Coroutine lightOffCoroutine;
public Light[] lights;
public KeyCode controlKey = KeyCode.X;
private bool on = false;
void Start() {
}
void Update() {
if (Input.GetKeyDown (controlKey)) {
on = !on;
if (!on) {
lightOnCoroutine = StartCoroutine ("ChangeLight");
if(lightOffCoroutine != null) {
StopCoroutine(lightOffCoroutine);
}
}
if (on) {
lightOffCoroutine = StartCoroutine ("StopLight");
if(lightOnCoroutine != null) {
StopCoroutine(lightOnCoroutine);
}
}
}
IEnumerator ChangeLight() {
int i = 0;
while(true) {
lights*.enabled = false;*
i++;
if(i > lights.length - 1) {
i = 0;
}
lights*.enabled = true;*
yield return WaitForSeconds(1);
}
}
}
}
Fixed several things, should work now! Just add your other coroutine now!
using UnityEngine;
using System.Collections;
public class LightAnimator : MonoBehaviour {
Coroutine lightOnCoroutine;
Coroutine lightOffCoroutine;
public Light[] lights;
public KeyCode controlKey = KeyCode.X;
private bool on = false;
void Start() {
}
void Update()
{
if (Input.GetKeyDown (controlKey))
{
on = !on;
if (!on)
{
lightOnCoroutine = StartCoroutine ("ChangeLight");
if (lightOffCoroutine != null)
{
StopCoroutine (lightOffCoroutine);
}
}
if (on)
{
lightOffCoroutine = StartCoroutine ("StopLight");
if (lightOnCoroutine != null)
{
StopCoroutine (lightOnCoroutine);
}
}
}
}
IEnumerator ChangeLight()
{
int i = 0;
while(true)
{
lights*.enabled = false;*
_ lights*.enabled = true;_
_ yield return new WaitForSeconds(1);_
_ }_
_ }_
_}*_
Line 37 needs to read:
yield return new WaitForSeconds(1);
WaitForSeconds is a class, so what you’re really doing here is creating an instance of the class and returning it as the function result. In order to create a new class you must use the new keyword.
Isn’t your IEnumerator method declared inside Update? Declare methods inside a class but not inside other methods. Move it out of Update.