0% found this document useful (0 votes)
7 views5 pages

Using System

The document describes a script for placing and scaling furniture objects in an augmented reality scene using touch input. It detects touches to raycast and spawn furniture objects at hit positions on planes. It also scales spawned objects using multi-touch pinch gestures.

Uploaded by

Abir Gharbi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Using System

The document describes a script for placing and scaling furniture objects in an augmented reality scene using touch input. It detects touches to raycast and spawn furniture objects at hit positions on planes. It also scales spawned objects using multi-touch pinch gestures.

Uploaded by

Abir Gharbi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

using System.

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

using UnityEngine.UI;
using UnityEngine.EventSystems;

using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
using Unity.XR.CoreUtils;

public class furniturePlaceManagment : MonoBehaviour


{
public GameObject SpawnbleFurniture;
public XROrigin sessionOrigin;
public ARRaycastManager raycastManager;
public ARPlaneManager planeManager;
GameObject _object;

Vector2 First_touch;
Vector2 Second_touch;
float distance_current;
float distance_previous;
bool First_pinch=true;

private List<ARRaycastHit> raycastHits = new List<ARRaycastHit>();

private void Update()


{
if(Input.touchCount > 0 && isButtonPressed() == false)
{
if(Input.GetTouch(0).phase == TouchPhase.Began)
{
bool collision =
raycastManager.Raycast(Input.GetTouch(0).position,
raycastHits,TrackableType.PlaneWithinPolygon);

if(collision){
GameObject _object = Instantiate(SpawnbleFurniture);
_object.transform.position = raycastHits[0].pose.position;
_object.transform.rotation = raycastHits[0].pose.rotation;
}

foreach (var planes in planeManager.trackables)


{
planes.gameObject.SetActive(false);
}

planeManager.enabled = false;
}
if(Input.touchCount > 1 && _object)
{

First_touch = Input.GetTouch(0).position;
Second_touch=Input.GetTouch(1).position;
distance_current=Second_touch.magnitude-First_touch.magnitude;
if(First_pinch)
{
distance_previous=distance_current;
First_pinch=false;
}
if(distance_current!= distance_previous)
{
Vector3 scaleValue =
_object.transform.localScale*(distance_current/distance_previous);
_object.transform.localScale=scaleValue;
distance_previous=distance_current;

}
}

}
else{
First_pinch = true;
}

}
public bool isButtonPressed(){
if(EventSystem.current.currentSelectedGameObject?.GetComponent<Button>()
== null){
return false;
}
else {
return true;
}

public void SwitchFurniture(GameObject furniture){


SpawnbleFurniture = furniture;
}

You might also like