StartCourutine works on AWAKE but don't in START method

So that’s basically it. When I call StartCorutine method in start nothing happens, but it works in AWAKE.
Does anyone know why?
The script it’s attached to the TeleportObject.

I’ve created another GameManager.cs and attached it to a new GameObject in the scene. I’ve wrote the logic there and it works with the Start method.
So it seems it has something to do with the place where the script it’s attached to.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;

// GameDev.tv Challenge Club. Got questions or want to share your nifty solution?
// Head over to - http://community.gamedev.tv

public class Teleport : MonoBehaviour
{
    [SerializeField] Transform teleportTarget;
    [SerializeField] GameObject player;
    [SerializeField] Light areaLight;
    [SerializeField] Light mainWorldLight;
    [SerializeField] GameObject nextTeleport;
    [SerializeField] private float timeBetweenLightning = 6f;
    [SerializeField] private int lightningRounds = 4;

    private Light worldLight;
    private int randomLightningFlahes;


    private void Awake()
    {
        worldLight = GameObject.FindWithTag("WorldLight").GetComponent<Light>();
        StartCoroutine(BlinkWorldLightRoutine());
        
    }

    private void Start()
    {
        
    }


    void OnTriggerEnter(Collider other) 
    {
        // Challenge 2: TeleportPlayer();
        if (other.GetComponent<FirstPersonMovement>())
        {
            TeleportPlayer(other);

            // Challenge 3: DeactivateObject();
            DeactivateObject();
            // Challenge 4: IlluminateArea();
            IlluminateArea();
        }

        // Challenge 5: StartCoroutine ("BlinkWorldLight");
        // Challenge 6: TeleportPlayerRandom();
    }

    void TeleportPlayer(Collider player)
    {
        if (teleportTarget)
        {
            player.transform.position = teleportTarget.position;
        }
    }

    void DeactivateObject()
    {
       this.gameObject.GetComponent<Teleport>().teleportTarget = null;
       GetComponentInChildren<Light>().enabled = false;
    }

    void IlluminateArea()
    {
        if (nextTeleport)
        {
            nextTeleport.GetComponentInChildren<Light>().enabled = true;
        }
    }


    private IEnumerator BlinkWorldLightRoutine()
    {
        randomLightningFlahes = Random.Range(1, lightningRounds);
        Debug.Log("Empieza la corutina");
        yield return new WaitForSeconds(Random.Range(2f, timeBetweenLightning));
        
        for (int i = 0; i <= randomLightningFlahes; i++)
        {
            Debug.Log("Entro al loop numero " + (i+1) );
            yield return new WaitForSeconds(.1f);
            worldLight.intensity = 1;
            yield return new WaitForSeconds(.075f);
            worldLight.intensity = 0;
        }

        StartCoroutine(BlinkWorldLightRoutine());
    }


}

Privacy & Terms