【问题标题】:I am trying to make text fade in Unity, but the code in my for loop returns a NullReferenceException我试图让 Unity 中的文本淡入淡出,但我的 for 循环中的代码返回 NullReferenceException
【发布时间】:2019-11-09 04:24:14
【问题描述】:

我在 Unity 中制作手机游戏,我想让一些文字淡出。我创建了一个 for 循环,将文本颜色的 alpha 值增加了 255 倍。当我运行代码时,它给了我一个 NullReferenceException,说“对象引用未设置为对象的实例”。这是导致问题的 for 循环。

   {
       for(int alphaVal = 0; alphaVal < 256; alphaVal++)
       {
           text.color = new Color(red, green, blue, alphaVal);
       }
   }


【问题讨论】:

标签: c# unity3d mobile game-development


【解决方案1】:

您的text 变量未分配。确保将其拖入检查器。此外,统一颜色对象不接受 255 个值。它接受从 0 到 1 的浮点数。传入任何大于 1 的值将始终导致值 1(完整 alpha)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 2017-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多