unity day 4

编程跑马灯小游戏,感觉就学习了一个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&&timestop>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;
        }
    }
}

并没有实现随机,也没打算写下去了,因为写太乱,不想写了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值