A Day Night Cycle that you can use to get the time from
Hey guys. I'm trying to make a Day Night Cycle so that when i start the game It will start the cycle. I want it so that when the time variable is "6" then it will be at 6 o'clock. I also want it so that it is smooth. I am als trying to make it possible to be able to reference it from another script but that can be done later. Thanks in Advance
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DayNightCycle : MonoBehaviour { public float time = 0f; public Transform Sun; public Transform Moon; public float counter = 0f; private Quaternion targetRotation; public float smooth = 1f;
// Use this for initialization
void Start () {
time = 0f;
}
// Update is called once per frame
void FixedUpdate () {
counter += 1*Time.deltaTime;
if (counter >= 10f) {
transform.Rotate = Quaternion.Lerp(time, 0f, 0f);
time += 1f;
Debug.Log ("Hi");
counter = 0f;
}
counter += 1*Time.deltaTime;
}
}
Answer by NateLaw1988 · Aug 25, 2018 at 09:34 AM
here is my video with a link to a beautiful day night cycle. the video shows how to set it up
Your answer
Follow this Question
Related Questions
Stop transform translate sharply 1 Answer
C# I need to move object in a cycle 0 Answers
How to rotate 2 blocks using the center between the 2 blocks rather than center? 0 Answers
Trying to make sliding doors. With transform, but it jumps to position. What am I doing wrong? 1 Answer
Character speed changes with screen 0 Answers