Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

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

Discussion in 'Scripting' started by RubenVanOostveen, Oct 18, 2020.

  1. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91
    upload_2020-10-18_21-33-46.png

    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?
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
  3. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91
    [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.
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class EnterCar : MonoBehaviour
    7. {
    8.    
    9.     public AudioSource CarEnterAudio;
    10.     public AudioSource CarStartAudio;
    11.     public GameObject Camera;
    12.     public GameObject Player;
    13.     public GameObject ExitTrigger;
    14.     public GameObject Car;
    15.     public bool Check = false;
    16.  
    17.     void OnTriggerEnter(Collider other){
    18.       if (other.CompareTag("Player")){
    19.       Check = true;
    20.     }
    21.     }
    22.  
    23.     void OnTriggerExit(Collider other){
    24.       if (other.CompareTag("Player"))
    25.       Check = false;
    26.     }
    27.  
    28.     void Update()
    29.     {
    30.     if (Check == true && Input.GetKeyDown(KeyCode.E)){
    31.       Camera.SetActive(true);
    32.       Player.SetActive(false);
    33.       Debug.Log("lol");
    34.       ExitTrigger.SetActive(true);
    35.       CarEnterAudio.PlayOneShot(CarEnterAudio.clip);
    36.       yield return new WaitForSeconds(2);
    37.       CarStartAudio.PlayOneShot(CarStartAudio.clip);
    38.       yield return new WaitForSeconds(2);
    39.       Car.GetComponent<CarController>().enabled = true;
    40.  
    41.         }
    42.     }
    43. }
    44.  
    45.  
    This is my code btw