UniStorm Weather System Wiki
Advertisement


UniStorm Community Scripting

Here we allow UniStorm Members to help out the community by posting "UniStorm Helper Scripts". The helper scripts are little scripts people may find useful such as the one below. If you have a UniStorm Helper Script you'd like to share please post it here.


Important: We ask that you do not post our UniStorm Weather System scripts or any other of our code here, or anywhere else. This is strictly for helper scripts meaning anything that references UniStorm to perform a certain task or UniStorm releated event. 


Spawning a player with UniStorm

If you would like to have your player spawn, but still want to use UniStorm. Simply attach this script to your player prefab and it will grab all the needed UniStorm components and apply them.

C#

Create a simple HUD using 4.6 Beta UI system.

Create a canvas and 3 text objects.

Position your text objects where you would like them.

Set the canvas to screen space overlay.

Attach this script to a game object and populate the Text variables with your text objects in the inspector.

You should now see date, time and temperature in your new HUD.

If you wish to have temp in C rather than F the maths for it is as follows:


°F to °C Deduct 32, then multiply by 5, then divide by 9


/Paul.

@bigfiregamesUK

C#

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class HUD : MonoBehaviour {


	public Text DateTime;
	public Text WeatherType;
	public Text Temp;
	private int temp;
	private int weatherType;
	private string Weather;


	UniStormWeatherSystem_C WeatherScript;

	// Use this for initialization
	void Start () {

	 WeatherScript = GameObject.Find("UniStormSystemEditor").GetComponent<UniStormWeatherSystem_C>();
		if(WeatherScript ==null)

		{
			Debug.LogWarning ("script not found :(");
		}
	
	}
	
	// Update is called once per frame
	void Update () {
		weatherType =(int) WeatherScript.weatherForecaster;

		DateTime.text = WeatherScript.hourCounter.ToString () + ":" + WeatherScript.minuteCounter.ToString () + " " + WeatherScript.dayCounter.ToString () + "/" + WeatherScript.monthCounter.ToString () + "/" + WeatherScript.yearCounter.ToString();

		switch(weatherType)

		{
		case 1:
			Weather = "Foggy";
			break;
		case 2:
			Weather = "Rain or Snow";
			break;
		case 3:
			Weather = "Stormy";
			break;
		case 4:
			Weather = "Partly Cloudy";
			break;
		case 5:
			Weather = "Partly Cloudy";
			break;
		case 6:
			Weather = "Partly Cloudy";
			break;
		case 7:
			Weather = "Clear";
			break;
		case 8:
			Weather = "Clear";
			break;
		case 9:
			Weather = "Cloudy";
			break;
		case 10:
			Weather = "Butterflies";
			break;
		case 11:
			Weather = "Mostly Cloudy";
			break;
		case 12:
			Weather = "Heavy Rain";
			break;
		case 13:
			Weather = "Falling Leaves";
			break;
		default:
			break;


		}
		WeatherType.text = Weather;
		temp = WeatherScript.temperature;
		Temp.text = "Temp: " + temp.ToString() + "F";
	}

}

Have an Event Happen During a Certain Weather Type

This script will check the current UniStorm in-game weather. If it is equal to that of the entered weatherType within the sciprt, an event will happen.


JavaScript:

//UniStorm If Weather Type Example
//By: Black Horizon Studios

//Weather type number
var weatherType : int;

private var uniStormSystem : GameObject;

function Start () 
{
	uniStormSystem = GameObject.Find("UniStormParent_JS/UniStormSystemEditor");
}

function Update () 
{
	if (uniStormSystem.GetComponent(UniStormWeatherSystem_JS).weatherForecaster == weatherType) 
	{
     	     //If the number of the weather type of UniStorm is equal to the user's weather type have something happen here
	}
}


Disable or Enable UniStorm Particle Effects OnTrigger

Disabling or enabling UniStorm particle effects can be done by using the below code. This is especially useful if you want your player entering interiors and wanting the UniStorm particle effects disabled. 


JavaScript:

//UniStorm Disable/Enable Particles Example
//By: Black Horizon Studios

var enableEffects : boolean = false;
var disableEffects : boolean = false;

function OnTriggerEnter(other: Collider)
{  
   if (other.CompareTag("Player") && disableEffects && !enableEffects) 
   {	
    	for(var particleEmtr : ParticleRenderer in other.FindObjectsOfType(ParticleRenderer))
		{
			Debug.Log("Particle Effects have been disabled for player.");
			
   			particleEmtr.enabled = false;
		}
   }
   
   if (other.CompareTag("Player") && enableEffects && !disableEffects) 
   {
    	for(var particleEmtr : ParticleRenderer in other.FindObjectsOfType(ParticleRenderer))
		{
			Debug.Log("Particle Effects have been enabled for player.");
			
   			particleEmtr.enabled = true;
		}
   }
}



Check to See if the Current Temperature is Freezing or Not

Accessing the current UniStorm temperature can give some really nice gameplay and add tons of new features. Lets say your character will be in danger if it gets below freezing and their health or ablities will be affected if they're caught with a temperature 32 degrees or below. The below code checks to see if it's freezing or not and prints a debug log on whether it is or isn't. The only variable we advise using is the temperature variable.


JavaScript:

//UniStorm Check Temperature Example
//By: Black Horizon Studios

//How often should we check to see if it's freezing?
var checkTemperature : float;

private var checkTemperatureTimer : float;
private var uniStormSystem : GameObject;

function Start () 
{
	uniStormSystem = GameObject.Find("UniStormParent_JS/UniStormSystemEditor");
}

function Update () 
{
	//Used to check temperature only when checkTemperature's time is reached to avoid checking it every frame.
	checkTemperature += Time.deltaTime;
	
	if (checkTemperatureTimer >= checkTemperature && uniStormSystem.GetComponent(UniStormWeatherSystem_JS).temperature >= 33) 
	{
     	Debug.Log("It is above freezing");
     	
     	checkTemperature = 0;
     	
     	//Examples of resetting debilitating player effects when it's not freezing  	
     	//player.health = 100;
     	//player.speed = 8;
	}

	if (checkTemperatureTimer >= checkTemperature && uniStormSystem.GetComponent(UniStormWeatherSystem_JS).temperature <= 32) 
	{
    	Debug.Log("It is below freezing");
    	
    	checkTemperature = 0;
    	
    	//Examples of debilitating player effects do to with it being freezing
    	//player.health -= 0.01f * Time.deltaTime;
    	//player.speed = 4;
    	
	}
}

C#

//UniStorm Check Temperature Example
//By: Black Horizon Studios

using UnityEngine;
using System.Collections;

public class CheckTemperature : MonoBehaviour 
{
	//How often should we check to see if it's freezing?
	public float checkTemperature = 5;

	private float checkTemperatureTimer = 0.0f;
	private GameObject uniStormSystem;
	
	void Start () 
	{
		uniStormSystem = GameObject.Find("UniStormParent_JS/UniStormSystemEditor");
	}
	
	
	void Update () 
	{
		//Used to check temperature only when checkTemperature's time is reached to avoid checking it every frame.
		checkTemperature += Time.deltaTime;
	
		if (checkTemperatureTimer >= checkTemperature && uniStormSystem.GetComponent<UniStormWeatherSystem_C>().temperature >= 33) 
		{
     		Debug.Log("It is above freezing");
     	
     		checkTemperature = 0;
     	
     		//Examples of resetting debilitating player effects when it's not freezing  	
     		//player.health = 100;
     		//player.speed = 8;
		}

		if (checkTemperatureTimer >= checkTemperature && uniStormSystem.GetComponent<UniStormWeatherSystem_C>().temperature <= 32) 
		{
    		Debug.Log("It is below freezing");
    	
    		checkTemperature = 0;
    	
    		//Examples of debilitating player effects do to it being freezing
    		//player.health -= 0.01f * Time.deltaTime;
    		//player.speed = 4;
    	
		}
	}
}


Have an Event Happen at a Certain Time

Having things happen at a certain time using an in-game time or hour can really help make gameplay more dynamic and less static. Here is an example of a timed hour event. This event will only happen when UniStorm is between the starting and ending hours. This can be repeated or disabled if desired.

JavaScript:

//UniStorm Time Event Script Example
//By: Black Horizon Studios

var uniStormSystem : GameObject;

var startingHour : int;
var endingHour : int;

function Start () 
{
	uniStormSystem = GameObject.Find("UniStormParent_JS/UniStormSystemEditor");
}

function Update () 
{
	if (uniStormSystem.GetComponent(UniStormWeatherSystem_JS).hourCounter >= startingHour && uniStormSystem.GetComponent(UniStormWeatherSystem_JS).hourCounter <= endingHour)
	{
		//When the starting hour is reached the even starts. Once the ending hour is reached, the even is over.
		Debug.Log("A timed event is happening, you can make anything happen here.");
	}

        else
        {
                Debug.Log("The event has ended.");
        }

}

C#:

//UniStorm Time Event Script Example
//By: Black Horizon Studios

public GameObject uniStormSystem;

public int startingHour;
public int endingHour;

void Start () 
{
	uniStormSystem = GameObject.Find("UniStormParent_JS/UniStormSystemEditor");
}

void Update () 
{
	if (uniStormSystem.GetComponent<UniStormWeatherSystem_C>().hourCounter >= startingHour && uniStormSystem.GetComponent<UniStormWeatherSystem_JS>().hourCounter <= endingHour)
	{
	        //When the starting hour is reached the even starts. Once the ending hour is reached, the even is over.
		Debug.Log("A timed event is happening, you can make anything happen here.");
	}

        else
        {
                Debug.Log("The event has ended.");
        }
}



Activate an Array of Lights at Night

Activating lights at night can have a really cool effect and add to player immersion. Here you can use an array of lights and have UniStorm activate each of the lights within that array.


JavaScript:

//UniStorm 1.7
//@Black Horizon Studios

private var uniStormSystem : GameObject;
var hourOfEvent : int;
var eventTestBool : boolean;

var lightParent : GameObject;


function Awake () {

	//Find the UniStorm Weather System Editor, this must match the UniStorm Editor name
	uniStormSystem = GameObject.Find("UniStormSystemEditor");

}

function Start () {

	if (uniStormSystem == null)
		{
			//Error Log if script is unable to find UniStorm Editor
			Debug.LogError("<color=red>Null Reference:</color> You must have the UniStorm Editor in your scene and named 'UniStormSystemEditor'. Make sure your C# UniStorm Editor has this name. ");
		}

}

function Update () {

 
	if (uniStormSystem != null)
	{
		if (uniStormSystem.GetComponent(UniStormWeatherSystem_JS).hourCounter >= hourOfEvent && eventTestBool == false)
		{
			for(var gameObj : Light in lightParent.FindObjectsOfType(Light))
			{
   				gameObj.enabled = true;	
   				eventTestBool = true;
			}
				
		}
		
		if (uniStormSystem.GetComponent(UniStormWeatherSystem_JS).hourCounter >= 6 && uniStormSystem.GetComponent(UniStormWeatherSystem_JS).hourCounter <= 7 && eventTestBool == true)
		{
			for(var gameObj : Light in lightParent.FindObjectsOfType(Light))
			{
   				gameObj.enabled = false;	
   				eventTestBool = false;
			}
				
		}
	}

}


C#

//UniStorm 1.7 Script
//@Black Horizon Studios

using UnityEngine;
using System.Collections;

public class LightArray : MonoBehaviour {

private GameObject uniStormSystem;
private bool eventTestBool;
public int hourOfEvent;

public Light[] lights;

void Awake () {

	//Find the UniStorm Weather System Editor, this must match the UniStorm Editor name
	uniStormSystem = GameObject.Find("UniStormSystemEditor");

}

void Start () {

	if (uniStormSystem == null)
		{
			//Error Log if script is unable to find UniStorm Editor
			Debug.LogError("<color=red>Null Reference:</color> You must have the UniStorm Editor in your scene and named 'UniStormSystemEditor'. Make sure your C# UniStorm Editor has this name. ");
		}
		
	lights = FindObjectsOfType(typeof(Light)) as Light[];

}

void Update () {


	if (uniStormSystem != null)
	{
		if (uniStormSystem.GetComponent<UniStormWeatherSystem_C>().hourCounter >= hourOfEvent && eventTestBool == false)
		{
			
			
			foreach(Light gameObj in lights)
	
				{
   				gameObj.enabled = true;	
   				eventTestBool = true;
			}
				
		}
		
		if (uniStormSystem.GetComponent<UniStormWeatherSystem_C>().hourCounter >= 6 && uniStormSystem.GetComponent<UniStormWeatherSystem_C>().hourCounter <= 7 && eventTestBool == true)
		{	
				
			foreach(Light gameObj in lights)
			{
   				gameObj.enabled = false;	
   				eventTestBool = false;
			}
				
		}
	}

}
}
Advertisement