Norrec Norrec - 17 days ago 6
C# Question

The member XXX cannot be used as a method or delegate

I have done copied this of a tutorial online, but when I compile it shows 2 errors as below:

"Non-invocable member 'Feature.choices' cannot be used like a method" and
"The member `Feature.choices' cannot be used as method or delegate"


The last "choices" in the script has a red squiggly line. Any idea that might be wrong? Thanks in advanced, friends!

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);

}



}

Answer

Change this

renderer.sprite = choices(currIndex);

to this:

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