编程跑马灯小游戏,感觉就学习了一个Grid Layout Group组件,和熟悉下ugui得使用。
代码:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Specialized;
public class run : MonoBehaviour {
public Image[] touxiang=new Image[20] ;
bool start=false;
bool buttomdowntwo=false;
float time=0;
int i=0;
int temp=0;
int[] num = new int[4];
float timestop=10;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (start&×top>8) {
time += Time.deltaTime;
if (time < 0.1f) {
touxiang [i].color = new Color (0.5f, 0.5f, 0.5f, 0.5f);
} else {
touxiang [i].color = new Color (1, 1, 1, 1);
time = 0;
i++;
if (i > 18) {
i = 0;
}
}
}
if (buttomdowntwo&&temp<4) {
num [temp] = i;
if (temp >= 1) {
for (int j = 0; j <temp; j++) {
if (num [temp] == num [j]) {
temp--;
}
}
}
i = 0;
temp++;
buttomdowntwo = false;
}
if (temp > 0 && temp < 5) {
for (int j = 0; j < temp; j++) {
touxiang [num [j]].color = new Color (1, 1, 1, Random.Range (0, 1.0f));
}
}
}
public void getbuttomdown()
{
if (start == false) {
start = true;
} else {
start = false;
buttomdowntwo = true;
}
}
}
并没有实现随机,也没打算写下去了,因为写太乱,不想写了