Just need someone to look through and check what is wrong. The script is supposed to start a timer once the scene with this script is loaded, and when OnTriggerEnter2D is pressed, save the time (preferably in PlayerPrefs) and reset the timer. Once this process has happened nine times, it loads up a new scene and displays all of the times. Very much a beginner, so any help is really appreciated. Thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Timer : MonoBehaviour {
private List timers;
private float lastClickTime = -1;
private void Start()
{
timers = new System.Collections.Generic.List();
}
private void OnTriggerEnter2D (Collider2D other)
{
timers.Add(lastClickTime > 0 ? Time.time - lastClickTime : Time.time);
if (timers.Count == 9)
{
PlayerPrefs.SetFloat("RTime", 0f + Time.time);
print(PlayerPrefs.GetFloat("RTime"));
SceneManager.LoadScene("GamePanel", LoadSceneMode.Single);
}
}
}
↧