Search Unity

can't start Coroutine

Discussion in 'Scripting' started by Contact1, Jun 23, 2020.

  1. Contact1

    Contact1

    Joined:
    May 23, 2020
    Posts:
    3
    Hello I can't start the line where it says StartCoroutine(RespawnCo()); it's highlighting red can anyone help me please :( Thank you!!!


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class LevelManager : MonoBehaviour
    6. {
    7.     public static LevelManager instance;
    8.  
    9.     public float waitToRespawn;
    10.  
    11.     private void Awake()
    12.     {
    13.         instance = this;
    14.     }
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.        
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.        
    25.     }
    26.  
    27.     public void RespawnPlayer()
    28.     {
    29.         StartCoroutine(RespawnCo());
    30.     }
    31.  
    32.     private IEnumerable RespawnCo()
    33.     {
    34.         PlayerController.instance.gameObject.SetActive(false);
    35.  
    36.         yield return new WaitForSeconds(waitToRespawn);
    37.  
    38.         PlayerController.instance.gameObject.SetActive(true);
    39.     }
    40. }
    41.  
     

    Attached Files: