# Problem with Simple Script - Rotation and Data Types

Basically, this was supposed to be a small script for the sun of one of my projects. It simply sets the location of the sun in the sky with the location it is supposed to represent, and then proceeds to cycle the sun along the X axis at the rate determined by the ‘hoursInDay’ variable’

fortunately, the first part of the functionality works perfectly, though the second part has a ridiculous problem which I feel so stupid for not being able to solve. the ‘rot’ variable will not go to anything other than zero. I can manually enter the rotation speed in the Rotate function, but cannot use the variable no matter what I try… casting the original variable, ect. Would anyone be kind enough to nudge a newbie in the right direction?

``````#pragma strict

var hoursInDay = 1;

private var rot = 15 / (hoursInDay * 60 * 60 / 24);

function Start () {

//Setting the sun to the right position
var time = (System.DateTime.Now.Hour - 6);

transform.rotation.eulerAngles = new Vector3(15 * time, 0, 0);
}

function Update () {
transform.Rotate(rot * Time.deltaTime, 0, 0);
}
``````

#pragma strict

``````var hoursInDay = 1;

private var rot = 15 / (hoursInDay * 60 * 60 / 24);

function Start () {

//Setting the sun to the right position
var time = (System.DateTime.Now.Hour - 6);

transform.rotation.eulerAngles = new Vector3(15 * time, 0, 0);
}

function Update () {
transform.Rotate(rot * Time.deltaTime, 0, 0);
}
``````

There is an a very common error here. I will state one of the most common rookie error is you CANNOT assign a VAR a value OUTSIDE of a function. So your vars are not set to a value and they’re undefined. Do this to correct it.

``````#pragma strict

var hoursInDay: float;

private var rot: float;

function Start () {
//Assigning Variables
hoursInDay = 1;
rot = 15 / (hoursInDay * 60 * 60 / 24);

//Setting the sun to the right position
var time = (System.DateTime.Now.Hour - 6);

transform.rotation.eulerAngles = new Vector3(15 * time, 0, 0);
}

function Update () {
transform.Rotate(rot * Time.deltaTime, 0, 0);
}
``````

This should fix it. If there is another error comment and I will look at it again.