Question by
BoneOctopus · Nov 04, 2019 at 02:31 AM ·
timetimercounterrotation detectiondaycycle
Counting Days Using In-Game Time System?
I'm making a very simple game where the player simply watches the sunrise and sunset, and there's a counter that displays how many have occurred. My problem is, I have no idea how to have that number. I have the directional light rotating using this code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class sun : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update() {
transform.RotateAround(Vector3.zero,Vector3.right,15f*Time.deltaTime);
transform.LookAt(Vector3.zero);
}
}
I just want to store the number as a variable that I can input into a canvas at their feet. Does anyone know how to do this? All the tutorials I keep finding use our time, and I have a very fast day/night cycle in-game. I want the end result to say "You have watched X sunrises. Are you ready to move on?" and I'll have a "yes" option that ends the game (though I can probably figure out that last bit on my own)
Comment
Answer by xxmariofer · Nov 04, 2019 at 02:57 PM
public class sun : MonoBehaviour
{
public float time;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update() {
transform.RotateAround(Vector3.zero,Vector3.right,15f*Time.deltaTime);
transform.LookAt(Vector3.zero);
time += 15 * Time.deltaTime;
Debug.Log((time / 360).ToString() + " days have passed!");
}
}