Author Topic: Profiles change on trigger  (Read 357 times)

twbd

  • Newbie
  • *
  • Posts: 11
    • View Profile
Profiles change on trigger
« on: December 29, 2017, 12:40:48 PM »
Hi,

I have one more question. Is it possible to change weather on trigger. Like i'm crossing the box and it changes weather from sunny to rainy. I tried but couldn't find a profiles for the weather.

Thanks

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1587
    • View Profile
    • Tanuki Digital
Re: Profiles change on trigger
« Reply #1 on: December 29, 2017, 05:58:51 PM »
It's possible, yes, but you would need to code it yourself by making a reference to the Tenkoku object and then changing the appropriate weather variables.  You can read a bit about this starting on page 8 in the documentation... http://www.tanukidigital.com/tenkoku/documentation/

You would need to set up an object with a collider (and possibly a rigidbody too?) to act as the trigger mechanism, and then attach a component to the object that will control which weather settings you want to change.  The below example code should get you started...

Code: [Select]
using UnityEngine;
using System.Collections;

public class TenkokuTrigger : MonoBehaviour {

//Public Variables
public Collider trackObject;
public float blendTime = 5f;
public bool resetWhenExiting = true;
[Space(10)]
[Range(0f,1f)] public float amountCirrus;
[Range(0f,1f)] public float amountCumulus;
[Range(0f,1f)] public float amountRain;

//Private Variables
private Tenkoku.Core.TenkokuModule moduleObject;
private bool hasExited = false;
private bool hasEntered = false;
private float blendVal = 0f;
private float startValCirrus = 0f;
private float startValCumulus = 0f;
private float startValRain = 0f;


void Awake () {
//Reference Tenkoku Object
moduleObject = (Tenkoku.Core.TenkokuModule) FindObjectOfType(typeof(Tenkoku.Core.TenkokuModule));
}


void SaveSettings(){
startValCirrus = moduleObject.weather_cloudCirrusAmt;
startValCumulus = moduleObject.weather_cloudCumulusAmt;
startValRain = moduleObject.weather_RainAmt;
}


void BlendSettings(){
moduleObject.weather_cloudCirrusAmt = Mathf.SmoothStep(startValCirrus, amountCirrus, blendVal);
moduleObject.weather_cloudCumulusAmt = Mathf.SmoothStep(startValCumulus, amountCumulus, blendVal);
moduleObject.weather_RainAmt = Mathf.SmoothStep(startValRain, amountRain, blendVal);
}


void LateUpdate(){

//Blend Values in
if (hasEntered){
if (blendVal < 1f){
blendVal += (Time.deltaTime / blendTime);
BlendSettings();
} else {
hasEntered = false;
}
}

//Blend Values out
if (hasExited && resetWhenExiting){
if (blendVal > 0f){
blendVal -= (Time.deltaTime / blendTime);
BlendSettings();
} else {
hasExited = false;
}
}
}


void OnTriggerEnter(Collider collideObject){

//Init Value
if (collideObject == trackObject){
if (blendVal == 0f){
SaveSettings();
}
}
}

void OnTriggerStay(Collider collideObject){

//Set Blend Values Flag
if (collideObject == trackObject){
hasEntered = true;
hasExited = false;
}
}

void OnTriggerExit(Collider collideObject){
//Reset
if (collideObject == trackObject){
hasEntered = false;
hasExited = true;
}
}




}