Hello, i’m beginner to unity, and i only use Javascript, today i was forced to convert my js script to C#, always fails when because i don’t know much about arrays, this is the JS
var waypointContainer : GameObject;
private var waypoints : Array;
private var currentWaypoint : int = 0;
function Start () {
var potentialWaypoints : Array = waypointContainer.GetComponentsInChildren( Transform );
waypoints = new Array();
for ( var potentialWaypoint : Transform in potentialWaypoints ) {
if ( potentialWaypoint != waypointContainer.transform ) {
waypoints[ waypoints.length ] = potentialWaypoint;
}
}
}
function Update () {
}
function NavigateToWaypoint () {
var RelativeWaypointPosition : Vector3 = transform.InverseTransformPoint( Vector3( waypoints[currentWaypoint].position.x, transform.position.y, waypoints[currentWaypoint].position.z ) );
//AxisCarController.steerAI = RelativeWaypointPosition.x / RelativeWaypointPosition.magnitude;
if ( RelativeWaypointPosition.magnitude < 15 ) {
currentWaypoint ++;
if ( currentWaypoint >= waypoints.length ) {
currentWaypoint = 0;
}
}
}
And this is the C# script
using UnityEngine;
public class GetWayPoint : MonoBehaviour
{
// Fields
private int currentWaypoint;
public GameObject waypointContainer;
private Array waypoints;
// Methods
public override void Main()
{
}
public override void NavigateToWaypoint()
{
if (this.get_transform().InverseTransformPoint(new Vector3(RuntimeServices.UnboxSingle(UnityRuntimeServices.GetProperty(UnityRuntimeServices.GetProperty(this.waypoints.get_Item(this.currentWaypoint), "position"), "x")), this.get_transform().get_position().y, RuntimeServices.UnboxSingle(UnityRuntimeServices.GetProperty(UnityRuntimeServices.GetProperty(this.waypoints.get_Item(this.currentWaypoint), "position"), "z")))).get_magnitude() < 15)
{
this.currentWaypoint++;
if (this.currentWaypoint >= this.waypoints.get_length())
{
this.currentWaypoint = 0;
}
}
}
public override void Start()
{
Array componentsInChildren = this.waypointContainer.GetComponentsInChildren(typeof(Transform));
this.waypoints = new Array();
IEnumerator enumerator = UnityRuntimeServices.GetEnumerator(componentsInChildren);
while (enumerator.MoveNext())
{
object obj1 = enumerator.get_Current();
if (!(obj1 is Transform))
{
}
Transform transform = RuntimeServices.Coerce(obj1, typeof(Transform));
if (transform != this.waypointContainer.get_transform())
{
this.waypoints.set_Item(this.waypoints.get_length(), transform);
UnityRuntimeServices.Update(enumerator, transform);
}
}
}
public override void Update()
{
}
}
it’s giving me the error that the namespace Array couldn’t be found.
Please help me