Hello,
I have been trying to figure this thing out but I’m fairly new to coding so please bare with me if this is obvious. What I am trying to do is have a particle system run when the shift key is pressed, and then deactivate and reactivate it again once it is pressed a second time. It is supposed to act like a rocketboost from a jetpack strapped to the main character’s back. My current code is written below, but obviously it isn’t working as intended, since if I let go of the shift key and start moving around, the particles will vanish as well. The best solution would of course be able to have the particles stay until they die out, but I am not sure how I would even begin to code that. So if anyone could point me in the right direction, I’d very much appreciate it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RocketSmoke : MonoBehaviour
{
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
foreach (Transform rocketSmoke in this.transform)
{
if (Input.GetKey("left shift"))
{
rocketSmoke.gameObject.SetActive(true);
}
else if (!Input.GetKey("left shift") && !Mathf.Approximately(0.0f, Input.GetAxisRaw("Horizontal")) || !Mathf.Approximately(0.0f, Input.GetAxisRaw("Vertical")))
{
rocketSmoke.gameObject.SetActive(false);
}
}
}
}