你如何编程文本在Unity中淡出(使用c#)?

时间:2016-06-30 00:56:24

标签: c# animation unity3d 2d recipe

我对c#和Unity完全不熟悉,所以请不要关闭我的问题。

我正在关注" recipie"从一本名为 Unity 5.x Cookbook 的书中删除文字。我很确定我正确地编写了所有代码,但是当我尝试运行我的代码时,Unity控制台说这个 -

  

Assets / Scripts / fadeScript.cs(10,17):错误CS0246:类型或命名空间名称`CountdownTimer'无法找到。您是否缺少using指令或程序集引用?

我是新手,所以我不明白问题所在。这是我的代码 -

using UnityEngine;
using System.Collections;

using UnityEngine.UI;
using System;

public class fadeScript : MonoBehaviour {

// Al Variables
private CountdownTimer countdownTimer;
private Text fadeText;
private int fadeDuration = 5;
private bool fading = false;

void Start () {

    fadeText = GetComponent<Text>();
    countdownTimer = GetComponent<CountdownTimer>();
    StartFading(fadeDuration);

}

void Update () {
    if (fading) {

        float alphaRemaining = countdownTimer.GetProportionTimeRemaining();
        print (alphaRemaining);
        Color c = textUI.material.color;
        c.a = alphaRemaining;
        fadeText.material.color = c;

        if (alphaRemaining < 0.01) {

            fading = false;

        }

    }
}

    public void StartFading (int timerTotal) {

        countdownTimer.ResetTimer(timerTotal);
        fading = true;

    }

}

我的代码出了什么问题?我该怎么做才能解决它?提前致谢!

-George

PS - 我确保脚本已连接到实际文本,并且文本名称正确。

1 个答案:

答案 0 :(得分:0)

您的脚本不知道“CountdownTimer”是什么。显然,您的项目中没有名为“CountdownTimer”的脚本。您似乎忘了从食谱中添加它。该脚本似乎有两个名为GetProportionTimeRemainingResetTimer的函数。

PS:下次将错误The type or namespace name could not be found. Are you missing a using directive or an assembly reference?复制到谷歌中,您将获得所需的信息。