Files
beyond/Assets/3D Camera Rain Drops/Scripts/CameraRainDrops3D.cs
2024-11-20 15:21:28 +01:00

97 lines
3.0 KiB
C#

using UnityEngine;
public class CameraRainDrops3D : MonoBehaviour
{
private GameObject SmallDrops, MediumDrops, BigDrops, RainTrails; //get all rain drop types
public bool EnableRainTrails = true; //enable/disable rain trails for user
[Range(1, 3)]
public int RainDropsIntensity = 3; //set Rain drop intensity via slider for user
private int _intensity = 3; //set the rain intensity
private bool _trails = true; //property modifier
public bool EnableTrails { //property for enabling/disabling rain trails
get {
return _trails;
}
set {
_trails = value;
if(_trails){
RainTrails.SetActive(true);
}else{
RainTrails.SetActive(false);
}
}
}
public int RainIntensity { //property for setting rain intensity
get {
return _intensity;
}
set {
_intensity = value;
//if intensity set to more than 3
//reset to 3
if(_intensity > 3){
_intensity = 3;
}
//if intensity set to less than 1
//reset to 1
if(_intensity < 1){
_intensity = 1;
}
//enable/disable the appropriate drop objects
if(_intensity == 1){
BigDrops.SetActive(false);
MediumDrops.SetActive(false);
SmallDrops.SetActive(true);
}else if(_intensity == 2){
BigDrops.SetActive(false);
MediumDrops.SetActive(true);
SmallDrops.SetActive(true);
}else{
BigDrops.SetActive(true);
MediumDrops.SetActive(true);
SmallDrops.SetActive(true);
}
}
}
// Start is called before the first frame update
void Start()
{
//get each drop type by game object name
//and set it for it's correct variable
foreach (Transform child in transform)
{
if(child.gameObject.name == "Small"){
SmallDrops = child.gameObject;
}else if(child.gameObject.name == "Medium"){
MediumDrops = child.gameObject;
}else if(child.gameObject.name == "Big"){
BigDrops = child.gameObject;
}else{
RainTrails = child.gameObject;
}
}
//set the properties with the correct data
EnableTrails = EnableRainTrails;
RainIntensity = RainDropsIntensity;
}
void LateUpdate()
{
//set the properties with the correct data
EnableTrails = EnableRainTrails;
RainIntensity = RainDropsIntensity;
}
}