Error CS 0023 Help
Im getting this error,
Assets/Scripts/Part1Scripts/AIScripts/AITest.cs(32,29): error CS0023: The .' operator cannot be applied to operand of type
method group'
Anyone know how to fix it?
{
public GameObject[] enemypool;
public float elapsedTime = 0f;
public float repeatTime = 10f;
public GameObject[] objectPool;
private int currentIndex = 0;
public float startTime = 0f;
public float endTime = 10f;
private void Update()
{
Startt();
}
private void Startt()
{
Spawn();
}
public void Spawn()
{
elapsedTime += Time.deltaTime;
if (elapsedTime >= repeatTime)
{
int newIndex = Random.Range(0, objectPool.Length);
objectPool[currentIndex].SetActive(false);
enemypool[currentIndex].SetActive(false);
currentIndex = newIndex;
objectPool[currentIndex].SetActive(true);
elapsedTime -= repeatTime;
objectPool[currentIndex].SetActive(true);
Time();
}
}
public void Time()
{
startTime -= repeatTime;
objectPool[currentIndex].SetActive(false);
enemypool[currentIndex].SetActive(true);
}
}
If I could get a clue as to what in the example code is line 29, it would help.
Answer by Bunny83 · Jul 15, 2018 at 03:19 AM
You named your method "Time". Identifiers can only have one meaning within a certain context. So inside your class "Time" refers to your Time method. That means you can't use Time.deltaTime
as Time is a method within this context. You either have to use UnityEngine.Time.deltaTime
or rename your Time method. I would strongly recommend to rename the method as it's generally a bad idea to name anything like built-in classes or methods. Also it's a bad, non-descriptive name anyways. The method name should be a one or two word description of what it does.