成员XXX不能用作方法或委托

时间:2016-11-19 15:41:08

标签: c# unity3d unity5

我已经在网上复制了这个教程,但是当我编译它时会显示2个错误,如下所示:

“非可调用成员'Feature.choices'不能像方法一样使用”和 “成员`Feature.choices'不能用作方法或委托”

脚本中的最后一个“选择”有一条红色的波浪线。任何想法都可能是错的?谢谢高级朋友们!

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[ExecuteInEditMode]

public class FeatureManager : MonoBehaviour {

public List<Feature> features;
public int currFeature;

void OnEnable()
{
    LoadFeatures();
}
void OnDisable()
{
    SaveFeatures();
}
void LoadFeatures()
{
    features = new List<Feature>();
    features.Add(new Feature(("hair"), transform.FindChild("hair").GetComponent<SpriteRenderer>()));
}
void SaveFeatures()
{

}



}


[System.Serializable]
public class Feature
{
public string ID;
public int currIndex;
public Sprite[] choices;
public SpriteRenderer renderer;

public Feature(string id, SpriteRenderer rend)
{
    ID = id;
    renderer = rend;
    UpdateFeature();
        }

public void UpdateFeature()
{
    choices = Resources.LoadAll<Sprite>("Character/" + ID);

    if (choices == null || renderer == null)
        return;

    if (currIndex < 0)
        currIndex = choices.Length - 1;
    if (currIndex >= choices.Length)
        currIndex = 0;

    renderer.sprite = choices(currIndex);

}



}

1 个答案:

答案 0 :(得分:0)

更改此

renderer.sprite = choices(currIndex);

到此:

renderer.sprite = choices[currIndex]; // use square brackets not parenthesis