Show Particle on every cliick based on touch position on mobile

Hi.

First, I am new here, first post, just started with Unity and I am soooo amazed by it.
Second, I have a doubt :frowning:
I am trying to show a particle on every touch position on mobile. What I got after hours of google search is:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Menu : MonoBehaviour
{
    public ParticleSystem emitter;
 
    public void Update ()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            emitter.Play();
        }
    }
}

This is showing the Particle once in a fixed position (the original position the particle is in canvas).
I changed the Stop Action to Call Back and disabled Loop and Play on Awake in the Particle Inspectorā€¦ so every time I click, it shows again.
Thanks for any help on this.

This is not surprising - after all, you are not changing the position of the particle System at all. If you want the particles to appear at a certain Location, you will need to Change its Position. Then again, I only see you Setting up a ray, which is half way through the way to determining the world Location of the touch. I recommend you finish that first, and then move the Emitter thereā€¦

Thanks for the replyā€¦ I am trying the documentation but without luck. One of the documentation I tried was this one: Unity - Scripting API: Touch.position but its giving me errorsā€¦ I find it hard to get information from the source documentationā€¦

Try this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Menu : MonoBehaviour
{
    public ParticleSystem emitter;
    public float distFromCam=10; //distance of the emitter from the camera
    public void Update ()
    {
        if (Input.GetMouseButtonDown(0))
        {
           Vector3 pos=Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distFromCam));
           emitter.transform.position=pos;
           emitter.Play();
        }
    }
}

OMGā€¦ Dudeā€¦ YOU ROCKā€¦
Thanks a lot,

I know this isn`t part of your asset and still you helped meā€¦ amazingā€¦
I will keep an eye on your stuff hereā€¦

thanks again. :slight_smile:

Iā€™m instantiating prefab GameObjects into my scene. Multiples of the same prefab. Does your touch setup allow for me to drag or rotate them individually. I have been trying to implement a different solution, that treats all of the prefabs as the same object, which is totally not what we want of course, and so I am looking for another solution to solve this.