public void Update()
{
//InitGrid();
/*if(reset)
{
donePath = false;
solvedPath.Clear();
reset = false;
}
if(start == null || end == null)
{
if (sources != null && sources.Count >= 2)
{
start = sources[PathNode.startNode].GetInnerObject();
end = sources[PathNode.endNode].GetInnerObject();
}
if (start == null || end == null)
{
Debug.LogWarning("Need 'start' and or 'end' defined!");
enabled = false;
return;
}
}
startIndex = Closest(sources, start.transform.position);
endIndex = Closest(sources, end.transform.position);
if(startIndex != lastStartIndex || endIndex != lastEndIndex)
{
reset = true;
lastStartIndex = startIndex;
lastEndIndex = endIndex;
return;
}
for(int i = 0; i < sources.Count; i++)
{
if(AStarHelper.Invalid(sources[i]))
continue;
sources[i].nodeColor = nodeColor;
}
PulsePoint(lastStartIndex);
PulsePoint(lastEndIndex);
if(!donePath)
{
solvedPath = AStarHelper.Calculate(sources[lastStartIndex], sources[lastEndIndex]);
//GameObject enemy = GameObject.FindGameObjectWithTag("Enemy");
//enemy.GetComponent<EnemyController>().path = solvedPath;
//enemy.E
donePath = true;
}
// Invalid path
if(solvedPath == null || solvedPath.Count < 1)
{
Debug.LogWarning("Invalid path!");
reset = true;
enabled = false;
return;
}
// Draw path
for(int i = 0; i < solvedPath.Count - 1; i++)
{
if(AStarHelper.Invalid(solvedPath[i]) || AStarHelper.Invalid(solvedPath[i + 1]))
{
reset = true;
return;
}
Debug.DrawLine(solvedPath[i].Position + new Vector3(0, 3, 0), solvedPath[i + 1].Position + new Vector3(0, 3, 0), Color.cyan * new Color(0.0f, 0.0f, 1.0f, 0.5f));
}*/
}