FANDOM



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. 



Damage from Cold Temperature using UFPS (Can be used for any other damaging factors)

Damages your UFPS player when UniStorm's weather reaches 32 degrees or below.

To use simply apply to your UFPS Parent GameObject.

//Damage from UniStorm's Weather using UFPS
//Black Horizon Studios

using UnityEngine;
using System.Collections;

public class DamageFromUniStorm : MonoBehaviour 
{
	UniStormWeatherSystem_C uniStormSystem;		//Our UniStorm Script
	GameObject uniStormObject;

	public vp_FPPlayerDamageHandler playerDamageScript;		//The UFPS script that allows damage	

	public float coldDamageAmount; 		//Doesn't just have to be from cold. This can be for anything UniStorm related.

	public float checkTemperature = 10;		//How often the script checks the temperature. This also is how often the player is damaged when the temp is 32 or below
	public float checkTemperatureTimer = 0;

	//Get our components and store them so we don't have to use GetComponent in the update function
	void Start () 
	{
		playerDamageScript = GetComponent<vp_FPPlayerDamageHandler>();		//Our reference to the damage handler
		uniStormObject = GameObject.Find("UniStormSystemEditor");		
		uniStormSystem = uniStormObject.GetComponent<UniStormWeatherSystem_C>(); 	//Our reference to UniStorm
	}
	
	void Update ()
	{
		//Used to check temperature only when checkTemperature's time is reached to avoid checking it every frame.
		//This is also used to check how often the player is damaged from cold weather
		checkTemperatureTimer += Time.deltaTime;

		//It's above freezing
		if (checkTemperatureTimer >= checkTemperature && uniStormSystem.temperature >= 33)
		{
			checkTemperatureTimer = 0;		//Reset our timer and check when the time has been met
		}

		//It's below freezing
		if (checkTemperatureTimer >= checkTemperature && uniStormSystem.temperature <= 32)
		{
			playerDamageScript.Damage(coldDamageAmount);	//Damage our UFPS player using the vp_FPPlayerDamageHandler script
			checkTemperatureTimer = 0;		//Reset our timer and check when the time has been met
		}
	}
}


Random Weather by Pressing the R Key (Can be changed to any button)

This script will randomly change the weather by pressing the R key to any of the 13 weather types.

C#

using UnityEngine;
using System.Collections;

public class RandomWeather : MonoBehaviour {

	private GameObject uniStormSystem;
	private UniStormWeatherSystem_C uniStormSystemScript;
	
	void Awake ()
	{
		//Find the UniStorm Weather System Editor, this must match the UniStorm Editor name
		uniStormSystem = GameObject.Find("UniStormSystemEditor");
		uniStormSystemScript = uniStormSystem.GetComponent<UniStormWeatherSystem_C>();
	}
	
	void Update ()
	{
		if (Input.GetKeyDown(KeyCode.R))
		{
			uniStormSystemScript.weatherForecaster = Random.Range(1,13);
		}
	}
}

Disable Sun Shafts for going under water

This script is perfect for if you'd still like UniStorm running, but you'd like to have the Sun Shafts image effect disabled when your player goes under water.

1) Get the DisableEffectsUnderWater script and assign it to your player. (ensure that your player has some type of collider on it)

2) Where the script says "Sun Shafts Effect" assign the camera that has the Sun Shafts on it to this slot. The script will automatically grab the Sun Shafts.

3) Get some sort of game object that has a box collider on it and set its collider to IsTigger to true.

4) Position your newly created game object so that it is right where your water starts. (This is the trigger that will disable the Sun Shafts when you go underwater)

5) Get your newly created game object and create a tag called Water and set it on your newly created game object.

6) Add a Rigidbody component to your newly created game object and disable the Use Gravity and enable the IsKinematic.

Everything should work and when your player hits the trigger, the Sun Shafts should be disabled. We tested this, so if it doesn't work, be sure that you have set everything up correctly.

using UnityEngine;
using System.Collections;
using UnityStandardAssets.ImageEffects;

public class DisableEffectUnderWater : MonoBehaviour 
{
	
	public SunShafts _SunShaftsEffect;
	public string TagThatDisables = "Water";
	
	void OnTriggerEnter(Collider other) 
	{
		if (other.gameObject.tag == TagThatDisables)
		{
			//On trigger with water, disable Sun Shafts Image Effect
			_SunShaftsEffect.enabled = false;
		}
	}

	void OnTriggerExit(Collider other) 
	{
		if (other.gameObject.tag == TagThatDisables)
		{
			//On trigger with water, enable Sun Shafts Image Effect
			_SunShaftsEffect.enabled = true;
		}
	}
}

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#

public class HookupUniStorm : MonoBehaviour

{

#region fields

public GameObject unistorm;

public GameObject unicamera;

public GameObject rain;

public GameObject rainStreaks;

public GameObject snow;

public GameObject butterflies;

public GameObject mistFog;

public GameObject snowMistFog;

public GameObject mistCloud;

public GameObject windyLeaves;

public GameObject lightningBolt1;



#endregion



// Use this for initialization

void Start ()

{

unistorm = GameObject.FindGameObjectWithTag("UniStorm");



if (!ReferenceEquals (unistorm,null))

{



   UniStormWeatherSystem_C[] weathers = unistorm.GetComponentsInChildren<UniStormWeatherSystem_C>();

   UniStormWeatherSystem_C weather = weathers[0];

   if (!ReferenceEquals (weather,null))

   {

      weather.rain = rain;

      weather.snow = snow;

      weather.butterflies = butterflies;

      weather.mistFog = mistFog;

      weather.snowMistFog = snowMistFog;

      weather.mistCloud = mistCloud;

      weather.windyLeaves = windyLeaves;

      weather.lightningBolt1 = lightningBolt1;



      weather.cameraThing = unicamera;

   }

}

}



}

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 : UniStormWeatherSystem_JS;

var startingHour : int;
var endingHour : int;

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

function Update () 
{
	if (uniStormSystem.hourCounter >= startingHour && uniStormSystem.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 UniStormWeatherSystem_C uniStormSystem;

public int startingHour;
public int endingHour;

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

void Update () 
{
	if (uniStormSystem.hourCounter >= startingHour && uniStormSystem.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;
			}
				
		}
	}

}
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.