So what i’m trying to do is making an icon change sprites when something happens, yes is the UI image component, uno is the first sprite and dos is the second, OK is just to make sure you cant spam E and make the icon blink like crazy.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TelIcon : MonoBehaviour
{
Image yes;
public Sprite uno;
public Sprite dos;
public bool OK;
// Start is called before the first frame update
void Start()
{
yes = GetComponent<Image>();
OK = true;
}
// Update is called once per frame
void FixedUpdate()
{
if(OK == true){
if(Input.GetKey(KeyCode.Space)) {
StartCoroutine(hmm());
OK = false;
}
}
}
public IEnumerator hmm(){
yes.sprite = dos;
yield return new WaitForSeconds(1f);
yes.sprite = uno;
OK = true;
}
}
Instead of changing to the second icon after pressing E, then changing back after 1 second, it just stays as the first icon and doesn’t change what so ever. Can anyone help me with this please?