Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Why is this not working?

i wanted to make a flash effect if my hunger reaches the number 20. I wanted to enable my outline and than disable it after 2 sec. and than enable it again and do this whole thing again until my hunger is more than 20 but my script starts spaming my Debug.Log and is turning my outline on and off and is not waiting the 2 sec. why?


using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

using UnityEngine.EventSystems;

using System;


public class AEffects : MonoBehaviour

{

  private PlayerMovement playerMovement;

  private Outline outline;

  // Start is called before the first frame update

  void Start()

  {

    outline = GetComponent<Outline>();


    playerMovement = FindObjectOfType<PlayerMovement>();

  }


  // Update is called once per frame

  void Update()

  {

     


    if (playerMovement.hunger <= 20)

    {

      outline.enabled = true;

      StartCoroutine(Blincking());

    }

    if(playerMovement.hunger >= 20)

    {

      outline.enabled = false;

    }

  }


  IEnumerator Blincking()

  {

    outline.enabled = true;

    yield return new WaitForSeconds(2);

    Debug.Log("Time is up");

    outline.enabled = false;

    yield return new WaitForSeconds(2);


  }

}

Best Answer

Sign In or Register to comment.