Search Unity

Enumerator error CS0103 the SpeedRoutine doesn't exist? Not sure why this doesnt work?

Discussion in 'Editor & General Support' started by SpagPix, Jul 1, 2019.

  1. SpagPix

    SpagPix

    Joined:
    Oct 28, 2018
    Posts:
    1
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class player : MonoBehaviour
    {
    public int Speed;
    public int MaxSpeed;

    // Start is called before the first frame update
    void Start()
    {
    MaxSpeed = Random.Range(60, 120);
    StartCoroutine(SpeedRoutine());
    }
    // Update is called once per frame
    void Update()
    {
    IEnumerator SpeedRoutine()
    {
    while (true)
    {
    yield return new WaitForSeconds(1.0f);
    Speed += 5;
    if(Speed > MaxSpeed)
    {
    break;
    }
    }
    }
    }
    }
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    You can not define your Corutine inside of your update function.