Removed TOTU 103
This commit is contained in:
		
							
								
								
									
										88
									
								
								Assets/Rendering/Scripts/RotateAndMoveObject.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								Assets/Rendering/Scripts/RotateAndMoveObject.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | ||||
| using UnityEngine; | ||||
|  | ||||
| public class RotateAndMoveObjectAR : MonoBehaviour | ||||
| { | ||||
|     public GameObject furniture; | ||||
|     public Camera arCamera; | ||||
|     public float rotationSpeed = 100f; | ||||
|     public float moveSpeed = 0.01f; | ||||
|  | ||||
|     private bool isRotating; | ||||
|     private bool isMoving; | ||||
|     private Vector2 lastTouchPosition; | ||||
|  | ||||
|     // Update is called once per frame | ||||
|     void Update() | ||||
|     { | ||||
|         HandleRotation(); | ||||
|         HandleMovement(); | ||||
|     } | ||||
|  | ||||
|     void HandleRotation() | ||||
|     { | ||||
|         // Comprobar si hay un segundo dedo en la pantalla (para rotaci<63>n) | ||||
|         if (Input.touchCount == 1) | ||||
|         { | ||||
|             Touch touch = Input.GetTouch(0); | ||||
|  | ||||
|             if (touch.phase == TouchPhase.Began) | ||||
|             { | ||||
|                 lastTouchPosition = touch.position; | ||||
|                 isRotating = true; | ||||
|             } | ||||
|             else if (touch.phase == TouchPhase.Moved && isRotating) | ||||
|             { | ||||
|                 Vector2 touchDelta = touch.position - lastTouchPosition; | ||||
|                 float rotationAmount = touchDelta.x * rotationSpeed * Time.deltaTime; | ||||
|  | ||||
|                 // Rotar el objeto sobre el eje Y | ||||
|                 furniture.transform.Rotate(0, -rotationAmount, 0); | ||||
|  | ||||
|                 lastTouchPosition = touch.position; | ||||
|             } | ||||
|             else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) | ||||
|             { | ||||
|                 isRotating = false; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     void HandleMovement() | ||||
|     { | ||||
|         // Comprobar si hay un toque en la pantalla para mover el objeto | ||||
|         if (Input.touchCount == 1) | ||||
|         { | ||||
|             Touch touch = Input.GetTouch(0); | ||||
|  | ||||
|             if (touch.phase == TouchPhase.Began) | ||||
|             { | ||||
|                 Ray ray = arCamera.ScreenPointToRay(touch.position); | ||||
|                 if (Physics.Raycast(ray, out RaycastHit hit)) | ||||
|                 { | ||||
|                     if (hit.collider.gameObject == furniture) | ||||
|                     { | ||||
|                         isMoving = true; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             else if (touch.phase == TouchPhase.Moved && isMoving) | ||||
|             { | ||||
|                 // Calcular la nueva posici<63>n en el mundo | ||||
|                 Ray ray = arCamera.ScreenPointToRay(touch.position); | ||||
|                 if (Physics.Raycast(ray, out RaycastHit hit)) | ||||
|                 { | ||||
|                     // Mueve el mueble al punto donde toca el rayo | ||||
|                     furniture.transform.position = Vector3.Lerp( | ||||
|                         furniture.transform.position, | ||||
|                         hit.point, | ||||
|                         moveSpeed | ||||
|                     ); | ||||
|                 } | ||||
|             } | ||||
|             else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) | ||||
|             { | ||||
|                 isMoving = false; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Ignacio Gómez Puga
					Ignacio Gómez Puga