错误CS0029:无法隐式转换类型`UnityEngine.UI.Slider []'到'UnityEngine.UI.Slider'

时间:2015-11-21 22:57:20

标签: unity3d unity5

我在点击器游戏中添加滑块时会收到错误CS0029,以告知您添加了多少物品来购买商品。我正在关注YouTube视频以学习编程和Unity。

  

Assets / scripts / UpgradeManger.cs(20,17):错误CS0029:无法隐式转换类型UnityEngine.UI.Slider[]' to UnityEngine.UI.Slider'

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class UpgradeManger : MonoBehaviour {
    public Click click;
    public UnityEngine.UI.Text itemInfo;
    public float cost;
    public float count = 0;
    public int clickPower;
    public string itemName;
    private float basedCost;
    public Color standard;
    public Color afforable;
    private Slider _slider;

    void start () {
        basedCost = cost;
        _slider = GetComponentsInChildren<Slider>   ();
    }

    void Update (){
        itemInfo.text = itemName + " (" + count + ")" + "\nCost: " + cost + "/nPower: " + clickPower;

        _slider.value = click.gold / cost * 100;
    }

    public void PurchasedUpgrade() {
        if (click.gold >= cost) {
            click.gold -= cost;
            count += 1;
            click.goldperclick += clickPower;
            cost = Mathf.Round (cost * 1.15f);
            basedCost = Mathf.Pow (cost, basedCost = cost);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

[00:41]你正在使用GetComponentsInChildren而不是GetComponentInChildren [00:41] GetComponentsInChildren返回一个数组