You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.6 KiB
98 lines
2.6 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using DG.Tweening;
|
|
|
|
namespace Level25
|
|
{
|
|
|
|
public class L25MouseCtrl : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUpHandler
|
|
{
|
|
public Transform item;
|
|
public Transform camera;
|
|
public Transform seletedItem;
|
|
|
|
private bool isClick = false;
|
|
private Vector3 tempItemRote;
|
|
private Vector3 mouseClickPos;
|
|
private Vector3 mouseLastPos;
|
|
private int roteDir;
|
|
private Vector2 midPos;
|
|
|
|
private void Start()
|
|
{
|
|
midPos = new Vector2(Screen.width / 2, Screen.height / 2);
|
|
Debug.Log(midPos);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
|
|
|
|
|
|
float mouseX = Input.GetAxis("Mouse X");
|
|
float mouseY = Input.GetAxis("Mouse Y");
|
|
if (Input.GetMouseButton(0))
|
|
{
|
|
if (Mathf.Abs( mouseX) >=0.2f)
|
|
{
|
|
item.transform.Rotate(Vector3.up, -mouseX * 5, Space.World);
|
|
}
|
|
else if (Mathf.Abs(mouseY) >= 0.2f)
|
|
{
|
|
item.transform.Rotate(Vector3.right, -mouseY * 5, Space.World);
|
|
}
|
|
|
|
//camera.transform.RotateAround(item.position, Vector3.up, mouseX * 5);
|
|
//camera.transform.RotateAround(item.position, Vector3.right, mouseY * 5);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
isClick = true;
|
|
mouseClickPos = Input.mousePosition;
|
|
mouseLastPos = mouseClickPos;
|
|
tempItemRote = item.transform.localEulerAngles;
|
|
|
|
RaycastCheck();
|
|
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
isClick = false;
|
|
mouseClickPos = Vector2.zero;
|
|
mouseLastPos = Vector2.zero;
|
|
tempItemRote = Vector3.zero;
|
|
roteDir = 0;
|
|
}
|
|
|
|
public void RaycastCheck()
|
|
{
|
|
Ray ray = new Ray(seletedItem.position, seletedItem.forward);
|
|
RaycastHit hit;
|
|
if (Physics.Raycast(ray,out hit,1000))
|
|
{
|
|
Debug.Log(hit.transform.gameObject);
|
|
AnswerSelected answerSelected;
|
|
answerSelected = hit.transform.gameObject.GetComponent<AnswerSelected>();
|
|
if (answerSelected == null) return;
|
|
answerSelected.ChangeState();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|