“滑块”不包含“值”的定义

时间:2019-03-30 09:20:26

标签: slider

当我滑动UI滑块时,我想创建一些项目,它将出现一些文本。但是,当我完成编码后,就会出现错误。

  

错误CS1061:“滑块”不包含“值”的定义,并且找不到包含“滑块”类型的第一个参数的可访问扩展方法“值”(您是否缺少using指令或程序集引用? )

但是,如果我输入一个新项目,则不会出现错误。当我导入资产时,错误再次出现。

这是我的代码:

public class TextControl : MonoBehaviour {

public Slider Food;
public Slider Calories;
public Text States;
public Text Question;

public void Update()
{
    wordShown();
}
public void wordShown()
{
    if (Food.value >= 0.5f) 
    {
        if (Calories.value >= 0.5f) 
        {
            States.text = "INACTIVE, UNHEALTHY";
            Question.text = "What changes can make him be active and healthy?";
        } 
        else if (Calories.value < 0.5f) 
        {
            States.text = "ACTIVE, HEALTHY";
            Question.text = "What should he do to maintaian his fitness?";
        }
    } 
    else if (Food.value < 0.5f) 
    {
        if (Calories.value >= 0.5f) 
        {
            States.text =  "INACTIVE,UNHEALTHY";
            Question.text = "What classes of food should have consume by this person?";
        } 
        else if (Calories.value < 0.5f) 
        {
            States.text =  "ACTIVE, HEALTHY";
            Question.text = "High calorie associated with what type of food?";
        }
    }
}

}

2 个答案:

答案 0 :(得分:0)

好,我知道了。 实际上有一个名为slider.cs的脚本。所以我将其更改为sliderscript.cs。滑块是unity属性的名称。我们不能使用该属性作为脚本名称。

答案 1 :(得分:0)

我有另一种解决方法。

使用UnityEngine.UI.Slider而不是Slider,因为正如Kamil Digital所说,属性滑块和脚本滑块存在某种冲突。

示例:

>Typescript: Select TypeScript Version