- Home /
Starting and stop particle systems with timer
Hello, I have got this level (shown bellow) where I want the player to press a button in the interact zone, which will stop the emission of the water and allow the player to go through the invisible barrier. The water will then turn back on after a certain time and kill the player if they try to go through.
his is attached to the invisible collides using System.Collections; using System.Collections.Generic; using UnityEngine;
public class WaterfallCol : MonoBehaviour
{
private waterTrigger WaterTrigger;
public ParticleSystem water;
// Start is called before the first frame update
void Start()
{
WaterTrigger = GameObject.Find("InteractZone").GetComponent<waterTrigger>();
}
void OnTriggerEnter(Collision collision)
{
if (collision.gameObject.name == "player" && WaterTrigger.WaterOn == true) // If player is in water zone and water is on reset player
{
collision.transform.position = new Vector3(0f, 2.5f, 0f);
}
}
void Water()
{
if (WaterTrigger.WaterOn == true)
{
water.Play();
}
if (WaterTrigger.WaterOn == false)
{
water.Stop();
}
}
}
Then this is on the trigger zone:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class waterTrigger : MonoBehaviour
{
public bool WaterOn = true;
void Start()
{
StartCoroutine(ChangeWater());
}
private void Update()
{
Debug.Log(WaterOn);
}
void OnTriggerEnter (Collider gameObjectInformation) //if player is in area and x is pressed turn water off
{
if (gameObjectInformation.gameObject.name == "player")
{
if (Input.GetKeyDown(KeyCode.Joystick1Button2))
{
WaterOn = false;
}
}
}
public IEnumerator ChangeWater()
{
if (WaterOn == false)
{
yield return new WaitForSeconds(3);// time it takes for water to turn back on
WaterOn = true;
}
}
}
Your answer
Follow this Question
Related Questions
Emission not working on model 0 Answers
Is it possible to make emissive dice in Unity? 1 Answer
How to bake metallic reflexion from self illuminated static objects ? 0 Answers
How to get Bloom effect only on emissive materials HDRP Volume component 0 Answers
Using a sequence of frames as a material emissive map. 0 Answers