成员 XXX 不能用作方法或委托
The member XXX cannot be used as a method or delegate
我在网上复制了这个教程,但是编译时出现如下2个错误:
"Non-invocable member 'Feature.choices' cannot be used like a method" 和
"The member `Feature.choices' cannot be used as method or delegate"
脚本中的最后一个 "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);
}
}
改变这个
renderer.sprite = choices(currIndex);
对此:
renderer.sprite = choices[currIndex]; // use square brackets not parenthesis
我在网上复制了这个教程,但是编译时出现如下2个错误:
"Non-invocable member 'Feature.choices' cannot be used like a method" 和 "The member `Feature.choices' cannot be used as method or delegate"
脚本中的最后一个 "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);
}
}
改变这个
renderer.sprite = choices(currIndex);
对此:
renderer.sprite = choices[currIndex]; // use square brackets not parenthesis