CHUVA AUTOMÁTICA
2 participantes
Página 1 de 1
CHUVA AUTOMÁTICA
Eu estou usando um Script para chover no meu game, mas eu queria saber como eu posso colocar essa chuva automática, no momento eu coloquei pra a chuva começar quando eu apertar "Y" e queria colocar pra chuva começar e terminar em um período aleatório.
Script da chuva :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RainController : MonoBehaviour {
public ParticleSystem rain;
public ParticleSystem clouds;
public GameObject ground;
[Range(0.0001f,0.01f)]
public float transtionFactor;
//cloudProperties
[Range(0, 1000)]
public int cloudsCleanSkyAmount;
[Range(0, 1000)]
public int cloudsRainSkyAmount;
[Range(0, 1000)]
public int cloudsCleanSkyMaxAmount;
[Range(0, 1000)]
public int cloudsRainSkyMaxAmount;
public Color colorCloudCleanSky;
public Color colorCloudRainSky;
//RainProperties
[Range(0, 10000)]
public int RainAmount;
//SkyProperties
[Range(0f, 1f)]
public float ligthExposureCleanSky;
[Range(0f, 1f)]
public float ligthExposureRainSky;
//GroundProperties
[Range(0f, 1f)]
public float groundSpecularDry;
[Range(0f, 1f)]
public float groundSpecularWet;
[Range(-1.5f, 1.5f)]
public float groundNormalDry;
[Range(-1.5f, 1.5f)]
public float groundNormalWet;
private Material rainMaterial;
private Material cloudMaterial;
private Material groundMaterial;
private Material skyMaterial;
public bool isRaining;
// Use this for initialization
void Start () {
rainMaterial = rain.GetComponent<ParticleSystemRenderer> ().material;
cloudMaterial = clouds.GetComponent<ParticleSystemRenderer> ().material;
skyMaterial = RenderSettings.skybox;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Y)) {
isRaining = !isRaining;
}
ParticleSystem.MainModule cloudsMain = clouds.main;
ParticleSystem.MinMaxCurve emissionCloudRate = clouds.emission.rateOverTime;
ParticleSystem.EmissionModule emissionCloud = clouds.emission;
ParticleSystem.MinMaxCurve emissionRainRate = rain.emission.rateOverTime;
ParticleSystem.EmissionModule emissionRain = rain.emission;
Color cloudColor = cloudMaterial.GetColor ("_TintColor");
float skyExposure = skyMaterial.GetFloat ("_Exposure");
if(isRaining){
emissionCloudRate.constantMax = cloudsRainSkyAmount;
emissionCloudRate.constantMin = cloudsRainSkyAmount;
emissionCloud.rateOverTime = emissionCloudRate;
clouds.maxParticles = cloudsRainSkyMaxAmount;
cloudMaterial.SetColor ("_TintColor", Color.Lerp(cloudColor, colorCloudRainSky, transtionFactor));
emissionRainRate.constantMax = RainAmount;
emissionRainRate.constantMin = RainAmount;
emissionRain.rateOverTime = emissionRainRate;
skyMaterial.SetFloat("_Exposure", Mathf.Lerp(skyExposure,ligthExposureRainSky,transtionFactor));
}else{
emissionCloudRate.constantMax = cloudsCleanSkyAmount;
emissionCloudRate.constantMin = cloudsCleanSkyAmount;
emissionCloud.rateOverTime = emissionCloudRate;
clouds.maxParticles = cloudsCleanSkyMaxAmount;
cloudMaterial.SetColor ("_TintColor", Color.Lerp (cloudColor, colorCloudCleanSky, transtionFactor));
emissionRainRate.constantMax = 0;
emissionRainRate.constantMin = 0;
emissionRain.rateOverTime = emissionRainRate;
skyMaterial.SetFloat("_Exposure", Mathf.Lerp(skyExposure,ligthExposureCleanSky ,transtionFactor));
}
}
public void StartRain(){
isRaining = true;
}
public void StopRain(){
isRaining = false;
}
}
Script da chuva :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RainController : MonoBehaviour {
public ParticleSystem rain;
public ParticleSystem clouds;
public GameObject ground;
[Range(0.0001f,0.01f)]
public float transtionFactor;
//cloudProperties
[Range(0, 1000)]
public int cloudsCleanSkyAmount;
[Range(0, 1000)]
public int cloudsRainSkyAmount;
[Range(0, 1000)]
public int cloudsCleanSkyMaxAmount;
[Range(0, 1000)]
public int cloudsRainSkyMaxAmount;
public Color colorCloudCleanSky;
public Color colorCloudRainSky;
//RainProperties
[Range(0, 10000)]
public int RainAmount;
//SkyProperties
[Range(0f, 1f)]
public float ligthExposureCleanSky;
[Range(0f, 1f)]
public float ligthExposureRainSky;
//GroundProperties
[Range(0f, 1f)]
public float groundSpecularDry;
[Range(0f, 1f)]
public float groundSpecularWet;
[Range(-1.5f, 1.5f)]
public float groundNormalDry;
[Range(-1.5f, 1.5f)]
public float groundNormalWet;
private Material rainMaterial;
private Material cloudMaterial;
private Material groundMaterial;
private Material skyMaterial;
public bool isRaining;
// Use this for initialization
void Start () {
rainMaterial = rain.GetComponent<ParticleSystemRenderer> ().material;
cloudMaterial = clouds.GetComponent<ParticleSystemRenderer> ().material;
skyMaterial = RenderSettings.skybox;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Y)) {
isRaining = !isRaining;
}
ParticleSystem.MainModule cloudsMain = clouds.main;
ParticleSystem.MinMaxCurve emissionCloudRate = clouds.emission.rateOverTime;
ParticleSystem.EmissionModule emissionCloud = clouds.emission;
ParticleSystem.MinMaxCurve emissionRainRate = rain.emission.rateOverTime;
ParticleSystem.EmissionModule emissionRain = rain.emission;
Color cloudColor = cloudMaterial.GetColor ("_TintColor");
float skyExposure = skyMaterial.GetFloat ("_Exposure");
if(isRaining){
emissionCloudRate.constantMax = cloudsRainSkyAmount;
emissionCloudRate.constantMin = cloudsRainSkyAmount;
emissionCloud.rateOverTime = emissionCloudRate;
clouds.maxParticles = cloudsRainSkyMaxAmount;
cloudMaterial.SetColor ("_TintColor", Color.Lerp(cloudColor, colorCloudRainSky, transtionFactor));
emissionRainRate.constantMax = RainAmount;
emissionRainRate.constantMin = RainAmount;
emissionRain.rateOverTime = emissionRainRate;
skyMaterial.SetFloat("_Exposure", Mathf.Lerp(skyExposure,ligthExposureRainSky,transtionFactor));
}else{
emissionCloudRate.constantMax = cloudsCleanSkyAmount;
emissionCloudRate.constantMin = cloudsCleanSkyAmount;
emissionCloud.rateOverTime = emissionCloudRate;
clouds.maxParticles = cloudsCleanSkyMaxAmount;
cloudMaterial.SetColor ("_TintColor", Color.Lerp (cloudColor, colorCloudCleanSky, transtionFactor));
emissionRainRate.constantMax = 0;
emissionRainRate.constantMin = 0;
emissionRain.rateOverTime = emissionRainRate;
skyMaterial.SetFloat("_Exposure", Mathf.Lerp(skyExposure,ligthExposureCleanSky ,transtionFactor));
}
}
public void StartRain(){
isRaining = true;
}
public void StopRain(){
isRaining = false;
}
}
leonardolopes- Avançado
- PONTOS : 1997
REPUTAÇÃO : 3
Respeito as regras :
Re: CHUVA AUTOMÁTICA
Você pode fazer uma função para iniciar a chuva num tempo aleatório quando entra no mapa e depois chamar para parar:
Então você coloca no inspector quanto tempo quer aguardar (mínino e máximo) para a chuva começar e parar. O tempo tem q ser em segundos, mas você pode multiplicar por 60 dentro do Invoke para transformar em minutos.
- Código:
public float minTimeStart, maxTimeStart, minTimeEnd, maxTimeEnd;
private float timeToRain;
void Start(
timeToRain = RandomTime(float
minTimeStart, maxTimeStart);
Invoke("StartTheRain", timeToRain);
}
float RandomTime(float min, float max){
return Random.Range(min, ++max);
}
void StartTheRain(){
isRaining = true;
timeToRain = RandomTime (minTimeEnd, maxTimeEnd);
Invoke("EndTheRain", timeToRain);
}
void EndTheRain(){
isRaining = false;
}
Então você coloca no inspector quanto tempo quer aguardar (mínino e máximo) para a chuva começar e parar. O tempo tem q ser em segundos, mas você pode multiplicar por 60 dentro do Invoke para transformar em minutos.
Re: CHUVA AUTOMÁTICA
MayLeone, muito obrigado
eu estava querendo fazer isso a muito tempo, vc me salvou aqui.
eu estava querendo fazer isso a muito tempo, vc me salvou aqui.
leonardolopes- Avançado
- PONTOS : 1997
REPUTAÇÃO : 3
Respeito as regras :
Tópicos semelhantes
» Criar Chuva?
» [Ajuda] Sistema de Chuva
» [AJUDA] Sistema de chuva
» Porta automática
» Uma bool automática?
» [Ajuda] Sistema de Chuva
» [AJUDA] Sistema de chuva
» Porta automática
» Uma bool automática?
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos