Help Needed With js to c# Conversion For an Script that im going to use for day night cycle

Hello guys im trying to convert a js script to c# script,but im getting four errors in the lines(29,58,71,73).This script is used for simple day night cycle of a skybox…Any help will be much appreciated

Thank You :slight_smile:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Sky : MonoBehaviour {

    public float secondsPerMinute = 0.625f;

    public float startTime = 12.0f;

    public float latitudeAngle = 45.0f;
    public Transform sunTilt;

    private float day = 1;
    private float min = 0;

    private float textOffset;
    private Material skyMat;
    private Transform sunOrbit;

    public float smoothMin;
    public float roughSun;

    void Start()
    {
        skyMat = GetComponent<Renderer>().sharedMaterial;
        sunOrbit = sunTilt.GetChild(0);

       sunTilt.eulerAngles.x = Mathf.Clamp(latitudeAngle, 0, 90);

        TimeLoop(startTime);

        if (secondsPerMinute < 0.0167f)
        {
            secondsPerMinute = 0.0166666f;
        }
    }

    IEnumerator TimeLoop(float t)
    {
        min = Mathf.Floor(t * 60);

        while (true)
        {
            while (min < 1440)
            {
                yield return new WaitForSeconds(secondsPerMinute);
                min += 1;

            }
            day += 1;
            min = 0;
        }
    }

    void UpdateSkyOld()
    {
       textOffset = Mathf.Cos((((min) / 1440) * 2) * Mathf.PI)80.25f + 0.25f;
        skyMat.mainTextureOffset = new Vector2(textOffset, 0);

        roughSun = min;

    }

    void UpdateSky()
    {
        smoothMin = (Time.time / secondsPerMinute) + (startTime * 60);

        smoothMin = smoothMin - (Mathf.Floor(smoothMin / 1440) * 1440);

        sunOrbit.localEulerAngles.y = smoothMin / 4;
        textOffset = Mathf.Cos((((smoothMin) / 1440) * 2) * Mathf.PI) * 0.25f + 0.25f;
        skyMat.mainTextureOffset = new vector2(Mathf.Round((textOffset - (Mathf.Floor(textOffset / 360) * 360)) * 1000) / 1000, 0);

    }

    void Update()
    {
        UpdateSky();
    }







}

May help to say what the errors are. but…lets see.

Line 29. You can’t assign a value to x, you must assign a vector3 to eulerangles.
sunTIlt.eulerAngles = //some vector3

Line 71 is the same issue

Not sure what errors you’re getting on 58 or 73 atm.

1 Like

29/71 - you can’t assign directly to “eulerAngles.x”. Replace it with this style:

Vector3 newAngles = sunTilt.eulerAngles;
newAngles.x = Mathf.Clamp(latitudeAngle, 0, 90);
sunTilt.eulerAngles = newAngles;

58 - you’ve got numbers directly next to parentheses. Is that supposed to be multiplication? Use * before the “80.25f”

73 - Capitalize “Vector”

1 Like

Thank u so much…now its working… :slight_smile: