50 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using UnityEngine;
 | |
| 
 | |
| public class ScalateAndRotateObjectAR : MonoBehaviour
 | |
| {
 | |
|     public GameObject furniture;
 | |
|     public Camera arCamera;
 | |
|     public float rotationSpeed = 100f;
 | |
| 
 | |
|     private bool isRotating;
 | |
|     private Vector2 lastTouchPosition;
 | |
| 
 | |
|     // Update is called once per frame
 | |
|     void Update()
 | |
|     {
 | |
|         HandleRotation();
 | |
|     }
 | |
| 
 | |
|     void HandleRotation()
 | |
|     {
 | |
|         // Comprobar si hay un toque en la pantalla
 | |
|         if (Input.touchCount > 0)
 | |
|         {
 | |
|             Touch touch = Input.GetTouch(0);
 | |
| 
 | |
|             // Si el toque ha comenzado
 | |
|             if (touch.phase == TouchPhase.Began)
 | |
|             {
 | |
|                 lastTouchPosition = touch.position;
 | |
|                 isRotating = true;
 | |
|             }
 | |
|             // Mientras se arrastra el dedo en la pantalla
 | |
|             else if (touch.phase == TouchPhase.Moved && isRotating)
 | |
|             {
 | |
|                 Vector2 touchDelta = touch.position - lastTouchPosition;
 | |
|                 float rotatiorAmount = touchDelta.x * rotationSpeed * Time.deltaTime;
 | |
| 
 | |
|                 // Rotar el mueble sobre el eje Y
 | |
|                 furniture.transform.Rotate(0, -rotatiorAmount, 0);
 | |
| 
 | |
|                 lastTouchPosition = touch.position;
 | |
|             }
 | |
|             // Cuando el toque termina
 | |
|             else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
 | |
|             {
 | |
|                 isRotating = false;
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 | 
