cannot be an iterator block because "Void"..... error message

Perhaps you see what iam aming for. i want to enter the car play an sound waity for 2 seconds (Length of the door shutting) Then start the car sound (Sound it takes before the car gets started) then the player can control the vehicle. but I get that error how do I fix it?

Hi,

You need to have your wait in a Coroutine.
See the manual for an example: Unity - Scripting API: WaitForSeconds
So start a coroutine and have those waits and your performed actions there.

Another alternative for delays in some situations is Invoke.

P.S. Maybe next time you could use a code tags (and text), it’s not fun to zoom into a picture…

4 Likes

[QUOTE=“Olmi, post: 6430751, member: 159727”

P.S. Maybe next time you could use a code tags (and text), it’s not fun to zoom into a picture…[/QUOTE]
Pardon me, I look trough the Coroutine but I don’t understand how I need to implement it can i do it un my update do i need to make a new void. they don’t explain it there.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnterCar : MonoBehaviour
{
   
    public AudioSource CarEnterAudio;
    public AudioSource CarStartAudio;
    public GameObject Camera;
    public GameObject Player;
    public GameObject ExitTrigger;
    public GameObject Car;
    public bool Check = false;

    void OnTriggerEnter(Collider other){
      if (other.CompareTag("Player")){
      Check = true;
    }
    }

    void OnTriggerExit(Collider other){
      if (other.CompareTag("Player"))
      Check = false;
    }

    void Update()
    {
    if (Check == true && Input.GetKeyDown(KeyCode.E)){
      Camera.SetActive(true);
      Player.SetActive(false);
      Debug.Log("lol");
      ExitTrigger.SetActive(true);
      CarEnterAudio.PlayOneShot(CarEnterAudio.clip);
      yield return new WaitForSeconds(2);
      CarStartAudio.PlayOneShot(CarStartAudio.clip);
      yield return new WaitForSeconds(2);
      Car.GetComponent<CarController>().enabled = true;

        }
    }
}

This is my code btw