Objects getting spawned again and again on tapping

Hello everybody, I am doing a project of multiple object placement , I have used a script for placing objects and uses lean Touch for carrying out the interactions like (Scaling ,Rotation and translation) but whenever i try to tap on an already spawned ar object to carry out my interactions another object is getting spawned over the tapped one again and again, Please help me resolve this issue.

Here’s the code I’ am using,

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.XR.ARFoundation;
public class InputManager : MonoBehaviour
{

[SerializeField] private Camera arCam;
[SerializeField] ARRaycastManager _raycastManager;
List _hits = new List();
private Touch touch;
void Start()
{
}
void Update()
{
touch=Input.GetTouch(0);
if(Input.touchCount<0||touch.phase!=TouchPhase.Began)
{
return;
}
if(IsPointerOverUi(touch)) return;

Ray ray = arCam.ScreenPointToRay(touch.position);
if (_raycastManager.Raycast(ray, _hits))
{
Pose pose = _hits[0].pose;
Instantiate(DataManager.Instance.furniture, pose.position, pose.rotation);

}
}
bool IsPointerOverUi(Touch touch)
{
PointerEventData eventData = new PointerEventData(EventSystem.current);
eventData.position=new Vector2(touch.position.x, touch.position.y);
List results=new List();
EventSystem.current.RaycastAll(eventData,results);
return results.Count > 0;
}
}

Use code tags.

?

They mean to say to use the buttons on the top bar of the post edit text box to specify that the text is code, making it formatted more readibly.

public void Update()
{
    // Do Something
}

But anyway, on to your original problem.
I don’t see any logic in here that prevents this code from executing (spawning another object again per tap) unless the user is tapping in UI, and in the case that the user is tapping on UI and it’s still going through, you may need to debug your code to figure out why the code is not detecting what you need, either maybe the UI is not on the right layer, or is being missed by the raycast, or some other logic error is occuring.

1 Like

I’ll just add that Unity does not support Lean Touch. You should reach out to the author of the asset for questions about it.

yah i just added a button so that the instantiation of objects only take place when clicking that button , that resolved my issue.