So im making a multiplayer fps and im wondering how to trigger a particle effect from a click in a script and im using unity 2018.4
That’s about four or five questions all in one.
Break it apart:
-
“from a click”: any click? use Input.GetMouseButtonDown(0)
-
“trigger a particle”: do one of:
— have the particle system and call .Emit() on it
— instantiate a fresh copy of the particle system
- get it over the network: this is entirely dependent on your networking setup
And of course you need to decide where to position the particle system.
There is a red line under Emit()
This is my code
if (Input.GetMouseButtonDown(0))
{
particles.Emit();
}
You should already be on this page:
https://docs.unity3d.com/ScriptReference/ParticleSystem.Emit.html
Always start with the documentation.
I tried and it didnt work
Which part failed? Where did it get to? Only YOU can debug YOUR code.
To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.
Doing this should help you answer these types of questions:
- is this code even running? which parts are running? how often does it run?
- what are the values of the variables involved? Are they initialized?
Knowing this information will help you reason about the behavior you are seeing.
I just created a particle system on a GameObject, wrote a script to call .Emit(1) on the GetComponent() that was on this object and it works perfectly. That took 45 seconds.
using UnityEngine;
public class x : MonoBehaviour
{
void Update()
{
if (Input.GetMouseButtonDown(0))
{
GetComponent<ParticleSystem>().Emit(1);
}
}
}
6704935–770086–x.unitypackage (8.01 KB)