im a noob at scripting in general but i want to play a particle effect at my feet once ive pressed right click i might be asking for more but as a noob i would like some kind of explanation to make it easy to understand the script ![]()
3 Answers
3Simply add this script to your particle effect and space will toggle on and off.
using UnityEngine;
using System.Collections;
public class particleEffect : MonoBehaviour {
// Update is called once per frame
void Update () {
if(Input.GetKeyUp(KeyCode.Space))
gameObject.GetComponent<ParticleSystem>().enableEmission=!gameObject.GetComponent<ParticleSystem>().enableEmission;
}
}
It’s simple actually…
First make your particle system. You need to go to / GameObject => Create Other… => Particle System /
Then adjust particle settings in Inspector!
Then create a new script, I’m using JavaScript (or UnityScript) and Copy/Paste this command:
var particle : GameObject; // <- Here you drag your Particle System that is Attached to your Controller
function Start() // When the script loads, When Game Starts usualy
{
particle.particleSystem.enableEmission = false; // Particle OFF
}
function Update() // <- Update function (Every Frame/Always checking)
{
if(Input.GetMouseButtonDown(1)) // <- If Right(1) mouse button is DOWN and then...
{
particle.particleSystem.enableEmission = true; // <- Particle ON
}
}
So then add script to the player (Or empty game object in the scene that you will not delete) and then chose that Object / Player and in the in Inspector Drag’n’Drop your particle system that you created.
Then run the game. First your particle will not be there but when you press Right Mouse button Particle System will come up.
Hope this helps.
The one thing no one seems to be adding is how to make it happen at your feet. One thing you can do for that result is attach the above script given by Axternaly to an object that's located at your players feet. From what I'm seeing everyones answers here will simply start the particle effect but it wont start where you want it to.
– superluigiusing UnityEngine;
using System.Collections;
public class ParticleController: MonoBehaviour {
public GameObject particle;
RaycastHit hit;
void Start ()
{
particle.particleSystem.enableEmission = false;
}
// Update is called once per frame
void Update () {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Input.GetMouseButtonDown(0)){
if(Physics.Raycast(ray, out hit, 100f)) {
if (hit.collider.bounds.Contains(particle.transform.position)) {
particle.particleSystem.enableEmission = true;
}
}
}
}
}
Just simply drag the script on your player and drag the gameObject with the particle system into the variable. And click play, there you go.
– helloiam

Also a noob at asking questions. Ask a short question in the subject, and give us details in the body. Also, simply type your question into google and look at a page or two of results, as this has been asked/answered many times.
– DaveAHave you researched: - [ParticleSystem][1] - [Input.GetMouseButtonDown()][2] - Parent/child relationships of game objects [1]: http://docs.unity3d.com/Documentation/Manual/ParticleSystems.html [2]: http://docs.unity3d.com/Documentation/ScriptReference/Input.GetMouseButtonDown.html
– robertbu