HOME

Hey Stranger

This is # cintix.dk and here you will find resources for developing Unity 3D and Java. I'm currently working on updating my website and upload resources to GitHub .
All the resources you can find on my site are FREE , And they will stay that way. If you like my work, then feel free to send me a donation from the menu, to keep me running on coffee ;-)

 

Right now I'm working on build a PlugIn for creating Day and Night cycles in Unity 3D . I have only just started, but this is what I got so fare.
They main thought it that user can set a day cycle (let's say 4 hours is one day) or manual with set the time of day. They script will use any lighting, that user want, so they can customize the lighting and shadows on there own. The plugin just turns it like the Sun, and giving the Day and Night effect. Then my plan is to give the option of added 2 or more skyboxes to the settings that will be blended withing the time of day.

using UnityEngine;
using System.Collections;
public class DayAndNightCycle : MonoBehaviour {
	public GameObject worldLight;
	public bool drawDome;
	[Range(1,100)]
	public int worldDomeScale = 5; 
	private Bounds _bounds;
	private Light _light;
	private GameObject _worldDome;
	private int lastSec = 0;
	private float _domeInternalSize;
	// Use this for initialization
	void Start () {
		GetMyBounds ();
		if (worldLight != null) {
			_light = worldLight.GetComponent<Light>();
			if (_light == null) {
				Debug.Log ("Sorry you World light Object, doesnt contain a Light! Please and a light to the World light object");
				return;
			}
			_worldDome = new GameObject ("WorldDome");
			_domeInternalSize = _bounds.size.x;
			if (_bounds.size.z > _domeInternalSize) _domeInternalSize = _bounds.size.z;
			if (_bounds.size.y > _domeInternalSize) _domeInternalSize = _bounds.size.y;
			_worldDome.transform.position = _bounds.center;
			_worldDome.transform.localScale = (new Vector3(_domeInternalSize, _domeInternalSize, _domeInternalSize)) * worldDomeScale;
			_light.transform.parent = _worldDome.transform;
			_light.transform.position = Vector3.up * ((_domeInternalSize * worldDomeScale) /2);
			_light.transform.eulerAngles = new Vector3 (90, 0, 0);
		}
	}
	void OnDrawGizmosSelected() {
		if (drawDome) {
			Gizmos.color = Color.yellow;
			Gizmos.DrawWireSphere (_bounds.center, ((_domeInternalSize * worldDomeScale) /2));
		}
	}
	// Update is called once per frame
	void Update() {
		GetMyBounds();	
		if (_light != null)
			_light.transform.LookAt (_bounds.center);
		int sec = System.DateTime.Now.Second;
		if (sec > lastSec) {
			Debug.Log ("sec " + sec + " last sec : " + lastSec);
			_worldDome.transform.Rotate (Vector3.forward * (360/60));
			lastSec = sec;
		} else if (sec < lastSec)
			lastSec = 0;
	}
	private void GetMyBounds() {
		_bounds = new Bounds();
		Renderer[] renders = GetComponentsInChildren<Renderer>();
		foreach (Renderer render in renders) {
			_bounds.Encapsulate (render.bounds);
		}
	}
}

 

 

 

 

 

Lastest News