Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Im wondering how to trigger a particle effect from a click in unity 2018.4

Discussion in 'Scripting' started by dannyboi20188, Jan 8, 2021.

  1. dannyboi20188

    dannyboi20188

    Joined:
    Jan 8, 2021
    Posts:
    3
    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
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,930
    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.
     
  3. dannyboi20188

    dannyboi20188

    Joined:
    Jan 8, 2021
    Posts:
    3
    There is a red line under Emit()
    This is my code


    Code (CSharp):
    1. if (Input.GetMouseButtonDown(0))
    2. {
    3.     particles.Emit();
    4. }
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,930
  5. dannyboi20188

    dannyboi20188

    Joined:
    Jan 8, 2021
    Posts:
    3
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,930
    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<ParticleSystem>() that was on this object and it works perfectly. That took 45 seconds.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class x : MonoBehaviour
    5. {
    6.     void Update()
    7.     {
    8.         if (Input.GetMouseButtonDown(0))
    9.         {
    10.             GetComponent<ParticleSystem>().Emit(1);
    11.         }
    12.     }
    13. }
    14.  
     

    Attached Files: