How would I accomplish having an object only visible when input is held down? I’m trying to make it so when my character in my game sprints the particle for cloud puffs that are attached to the feet will be visible. Here is my script so far;
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class SprintParticleController : MonoBehaviour {
void Start () {
// You can use particleSystem instead of
// gameObject.particleSystem.
// They are the same, if I may say so
GetComponent<ParticleSystem>().emissionRate = 1;
}
void Update () {
if (Input.GetButtonDown("Sprint")) {
GetComponent<ParticleSystem>().Emit(1000);
}
}
}
You can Enable/Disable components according to your need by “.enabled = true/false”.
You can also Activate/ Deactivate Game Objects by “gameObject.SetActive(false/true)”
But this time you only need .enabled functionality.
void Start () {
// You can use particleSystem instead of
// gameObject.particleSystem.
// They are the same, if I may say so
GetComponent<ParticleSystem>().emissionRate = 1;
// Disable your particle system.
GetComponent<ParticleSystem>().enabled = false;
}
void Update () {
// Enable particle system when "Sprint" button is pressed down
if (Input.GetButtonDown("Sprint")) {
GetComponent<ParticleSystem>().enabled = true;
GetComponent<ParticleSystem>().Emit(1000);
}
// Disable again when "Sprint" button is released
if (Input.GetButtonUp("Sprint")) {
GetComponent<ParticleSystem>().enabled = false;
}
}