i am trying switch case Randomly switch every second and i am trying to create a start button for my time ,if everyone can help please do thanks
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ChangeImages : MonoBehaviour
{
int n;
int n2;
public Image imageView1;
public Image imageView2;
public Text timerLabel;
public float mycoolTimer = 3;
private Text TimerText;
void Start()
{
TimerText = GetComponent<Text>();
}
void Update()
{
mycoolTimer -= Time.fixedDeltaTime;
TimerText.text = mycoolTimer.ToString("f0");
print(mycoolTimer);
if (mycoolTimer < 0)
{
Time.timeScale = 0;
}
}
void TimerUpdate(){
n = Random.Range(0, 4);
switch (n)
{
case 0:
imageView1.sprite = Resources.Load<Sprite>("Image/blu") as Sprite;
break;
case 1:
imageView1.sprite = Resources.Load<Sprite>("Image/n1") as Sprite;
break;
case 2:
imageView1.sprite = Resources.Load<Sprite>("Image/n2") as Sprite;
break;
case 3:
imageView1.sprite = Resources.Load<Sprite>("Image/n3") as Sprite;
break;
default:
break;
}
n2 = Random.Range(0, 4);
switch (n2)
{
case 0:
imageView2.sprite = Resources.Load<Sprite>("Image/blu") as Sprite;
break;
case 1:
imageView2.sprite = Resources.Load<Sprite>("Image/n1") as Sprite;
break;
case 2:
imageView2.sprite = Resources.Load<Sprite>("Image/n2") as Sprite;
break;
case 3:
imageView2.sprite = Resources.Load<Sprite>("Image/n3") as Sprite;
break;
default:
break;
}
Comment