The script gives this error. I couldn’t solve it, can you help me?
ERROR : Assets\Scripts\signal.cs(54,53): error CS1001: Identifier expected
ERROR : Assets\Scripts\signal.cs(63,53): error CS1001: Identifier expected
These are the wrong lines :
(54,53) : yield WaitForSeconds(indicatorDelayBetweenFlashes); //Delay between flashes of indicator
(63,53) : yield WaitForSeconds(indicatorDelayBetweenFlashes); //Delay between flashes of indicator
SCRIPT:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class signal : MonoBehaviour
{
public bool leftIndicatorEnabled = false; //If the left indicator is on
public bool rightIndicatorEnabled = false; //If the right indicator is on
private float indicatorDelayBetweenFlashes = 0.5f; //Delay between indicator flashes
public float leftIndicatorLight; //Set these to your lights
public float rightIndicatorLight; //Set these to your lights
void Update()
{
//Left indicator
if (Input.GetKeyDown(KeyCode.U)) //Left indicator button pressed
{
if (!leftIndicatorEnabled) //Is the indicator currently off?
{
rightIndicatorEnabled = false; //Turn off the right indicator
leftIndicatorEnabled = true; //Turn the left indicator on
LeftIndicatorFlasher(); //Flash the indicator
}
}
else //Indicator is on, lets turn if off.
{
leftIndicatorEnabled = false; //Turn off the left indicator
leftIndicatorLight.enabled = false; //Ensure the light is off
}
//Right Indicator
if (Input.GetKeyDown(KeyCode.I)) //Right indicator button pressed
{
if (!rightIndicatorEnabled) //Is the indicator currently off?
{
leftIndicatorEnabled = false; //Turn off the left indicator
rightIndicatorEnabled = true; //Turn the right indicator on
RightIndicatorFlasher(); //Flash the indicator
}
}
else //Indicator is on, lets turn if off.
{
rightIndicatorEnabled = false; //Turn off the right indicator
rightIndicatorLight.enabled = false; //Ensure the light is off
}
}
void LeftIndicatorFlasher()
{
while (leftIndicatorEnabled) //Loop until we turn the indicator off
{
leftIndicatorLight.enabled = !leftIndicatorLight.enabled; //Switch light from enabled to disabled and back again
yield WaitForSeconds(indicatorDelayBetweenFlashes); //Delay between flashes of indicator
}
}
void RightIndicatorFlasher()
{
while (rightIndicatorEnabled) //Loop until we turn the indicator off
{
rightIndicatorLight.enabled = !rightIndicatorLight.enabled; //Switch light from enabled to disabled and back again
yield WaitForSeconds(indicatorDelayBetweenFlashes); //Delay between flashes of indicator
}
}
}