Hey, I made 2 scripts for text, means everytime I press on a key the text appear for 3 seconds and fade out. I made one script for the text and one for the fade. so let say i press #1, a message appear.
It wroks great only for one time and only for one key, means if i want 2 texts, only one of them going to appear in play mode and only one time. I tried to duplicate the lines and you can see in the scripts but it dosent work…
any help?
the text script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIappeare : MonoBehaviour
{
[SerializeField] private Text customText;
[SerializeField] private Text customTextA;
void OnTriggerStay(Collider other)
{
if (other.tag == "Player" && Input.GetKeyDown(KeyCode.Alpha1))
{
customText.enabled = true;
}
if (other.tag == "Player" && Input.GetKeyDown(KeyCode.Alpha2))
{
customTextA.enabled = true;
}
}
}
the fade script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FadeOut : MonoBehaviour
{
public Text withFade;
public Text withFadeA;
// Start is called before the first frame update
void Start()
{
StartCoroutine(MovePlayer());
IEnumerator MovePlayer()
{
yield return new WaitForSeconds(3f);
withFade.canvasRenderer.SetAlpha(1f);
withFadeA.canvasRenderer.SetAlpha(1f);
fadeout();
}
// Update is called once per frame
void fadeout()
{
withFade.CrossFadeAlpha(0, 2, false);
withFadeA.CrossFadeAlpha(0, 2, false);
}
}
}