Here is my player script:
public class PlayerControler : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
public static Vector3 lastPosition;
private Rigidbody rb;
private int count;
void Start ()
{
rb = GetComponent<Rigidbody> ();
count = 0;
SetCountText ();
winText.text = "";
}
void Update ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
Vector3 lastPosition = transform.position;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 12) {
winText.text = "You Win!!";
}
}
}
//Destroy(other.gameObject);
And here is my camera script:
public class Accessor : MonoBehaviour {
void Start()
{
GameObject thePlayer = GameObject.Find("Player");
PlayerControler playerScript = thePlayer.GetComponent<PlayerControler>();
}
}
public class CameraController : MonoBehaviour {
public GameObject player;
public float moveSpeed = 5.0f;
private Vector3 offset;
public Transform target;
// Use this for initialization
// Update is called once per frame
void LateUpdate ()
{
transform.position = PlayerControler.lastPosition;
transform.LookAt (target);
}
}
I’m pretty sure it was originally from a tutorial, but still. The objective is for the camera to go to the position that the player was in the previous frame, and then point at the player now. It successfully points at the player, but it just stays in place. Help please