I want the covert javascript to C#
private var posStoreX : Array = [];
private var posStoreZ : Array = [];
function OnTouchBegin(pointCurrent : Vector3)
{
posStoreX.Clear(); //empties the array
posStoreZ.Clear(); //empties the array
}
function AddSplinePoint(pointStore : Vector3)
{
posStoreX[countDrag] = pointStore.x;
posStoreZ[countDrag] = pointStore.z;
countDrag ++;// next position
}
function FixedUpdate()
{
targetWaypoint = Vector3(posStoreX[countMove], 0 ,posStoreZ[countMove]);
}
When I covert the C# , have a lot of error , how to covert? thanks!!
I would do it like this:
// C#
using System.Collections.Generic;
public class MyClass : MonoBehaviour
{
public Vector3 targetWaypoint;
public int countMove = 0;
private var posStore = new List<Vector3>();
public void OnTouchBegin()
{
countMove = 0;
posStore.Clear(); //empties the array
}
public void AddSplinePoint(Vector3 pointStore)
{
pointStore.y = 0.0f;
posStore.Add(pointStore);
}
void Update() // It makes no sense to set the waypoint in Fixedupdate
{
if (countMove >= 0 && countMove < posStore.Count)
targetWaypoint = posStore[countMove];
}
}
You should use targetWaypoint = new Vector3(); instead of targetWaypoint = Vector3();