now what i am try to do is to create AI for enemy car in my racing game for that i have to create a path first so in order to do that i have written this script in which i am try to access child nodes of parent so for that i have created array and in which it is giving me error Transform pathTranform = GetComponentInChildren();
error is
Cannot implicitly convert type UnityEngine.Transform to UnityEngine.Transform
i am using this tutorial for path making Car AI Tutorial #1 (Unity 5 ) - Make the Path - YouTube
please help me out
thanks in advance
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class path : MonoBehaviour {
public Color lineColor;
private List<Transform> nodes = new List<Transform>();
void OnDrawGizmos()
{
Gizmos.color = lineColor;
Transform[] pathTranform = GetComponentInChildren<Transform>(); // here is the error
nodes = new List<Transform>();
for(int i = 1; i < pathTranform.Length; i++)
{
if(pathTranform[1] != transform)
{
nodes.Add(pathTranform*);*
}
}
for(int i = 0; i < nodes.Count; i++)
{
Vector3 CurrentNode = nodes*.position;*
Vector3 previousNode = Vector3.zero;
if(i > 0)
{
previousNode = nodes[i - 1].position;
}
else if(i == 0 && nodes.Count > 1)
{
previousNode = nodes[nodes.Count - 1].position;
}
Gizmos.DrawLine(previousNode, CurrentNode);
}
}
}