I'm trying to track playing position every 500ms which i can do but i need it to populate an array which i save to a txt file as a comma delimted list or something.
I have this code so far (which incorporates the player movement code too), which displays the positions in the console:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterControllerT : MonoBehaviour {
public float speed = 10.0f;
public Read_moveT ReadMove;
[SerializeField] private float _duration = 0.5f;
private float _timer = 0f;
public Vector3 PlayerPosT;
GameObject Mover;
public Vector3[] PlayerTxyz;
// Use this for initialization
void Start () {
Cursor.lockState = CursorLockMode.Locked;
Mover = GameObject.Find ("PlayerT");
ReadMove = Mover.GetComponent<Read_moveT> ();
}
// Update is called once per frame
void Update () {
if (!Input.GetButton ("DoorTrigger")) {
ReadMove.mUP = Input.GetAxis ("Vertical");
ReadMove.mLEFT = Input.GetAxis ("Horizontal");
float translation = ReadMove.mUP * speed;
float straffe = ReadMove.mLEFT * speed;
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
transform.Translate (straffe, 0, translation);
}
if (Input.GetKeyDown ("escape")) {
Cursor.lockState = CursorLockMode.None;
}
_timer += Time.deltaTime;
if (_timer >= _duration) {
_timer = 0f;
PlayerPosT = Mover.transform.position;
print ("Player:: X: " + PlayerPosT.x + ", Z: " + PlayerPosT.z);
}
}
}
I just need these coords to be saved into an array that i can process when the game is over. The problem being that the array will always be (until game over) of undetermined length.
Any ideas?
Thanks,
Paul..
List<Vector3>
? These can grow as needed to accommodate newlyAdd()
ed entries. \$\endgroup\$