Unity - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(197评价)
价格: 4431.00元
关于多张图片颜色循环显示问题
wuzq发起了问答2018-04-25
8
回复
794
浏览

想实现依次从左右到右显示红色。可是我显示的时候只在最后也就是第五张才显示红色。代码如下 

    public void DianButton()
    {
        for (int i = 0; i < image1.Length; i++)
        { 
            Thread.Sleep(1000);
            for (int j = 0; j < image1.Length; j++)
            {
                if (i == j)
                {
                    image1[i].color = Color.red;
                }
                else
                {
                    image1[i].color = Color.white;
                }
            }           
        }
    }

所有回复
  • siki 2018-04-25

    在unity里面使用协程,不要使用线程

    • wuzq 2018-04-25

      老师,我用了协诚,编译没错,运行出错了。
      出错提示ArgumentException: method return type is incompatible
      System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure)

      (0) 回复
    还有-4条回复,点击查看
    你还没有登录,请先登录注册
  • wuzq 2018-04-25

    线程和延时有啥区别,我使用延时也不行

     

    还有-5条回复,点击查看
    你还没有登录,请先登录注册
  • wuzq 2018-04-25
    public IEnumerator DianButton()
        {
            for (int i = 0; i < image1.Length; i++)
            { 
                yield return new WaitForSeconds(1);
                for (int j = 0; j < image1.Length; j++)
                {
                    if (i == j)
                    {
                        image1[i].color = Color.red;
                    }
                    else
                    {
                        image1[i].color = Color.white;
                    }
                }           
            }
        }

     

    还有-5条回复,点击查看
    你还没有登录,请先登录注册
  • siki 2018-04-26

    在按钮点击的时候,开启协程,不要把按钮被点击的方法修改为协程

    协程是伪线程,在unity里面使用协程就可以了

    还有-2条回复,点击查看
    你还没有登录,请先登录注册
发表回复
你还没有登录,请先 登录或 注册!