- Home /
I'm not sure what is wrong with my script
This is probably some noob mistake, but I have looked over this script a hundred times and I can't see why it doesn't work. It is supposed to record the time between mouse clicks clicking on a dot that moves randomly around the screen and displaying that time in a separate scene. For now I just want to display the time in the debug log and make sure that's working, and also the scene changing process, neither of which work right now. I'm a beginner and any help is appreciated, thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Timer : MonoBehaviour {
private List<float> timers;
private float lastClickTime = -1;
private void Start()
{
timers = new System.Collections.Generic.List<float>();
}
private void OnTriggerEnter2D (Collider2D other)
{
timers.Add(lastClickTime > 0 ? Time.time - lastClickTime : Time.time);
if (timers.Count == 9)
{
PlayerPrefs.SetFloat("RTime", 0f + Time.time);
Debug.Log (PlayerPrefs.GetFloat("RTime"));
SceneManager.LoadScene("GamePanel", LoadSceneMode.Single);
}
}
}
Your answer
Follow this Question
Related Questions
Not sure what is wrong with my timer script. 1 Answer
How do you save timer with PlayerPrefs? 1 Answer
Add more seconds to the timer when colliding with an object. 2 Answers
Playerprefs and Star rating system 2 Answers
Converting float to string with time format; sending variables to disabled game object 1 Answer