- Home /
Question by
hsnzkg · May 20, 2021 at 02:10 PM ·
movementinputmouseplayer movement
Input System Can't Catch Event on Update
I have some input styles like drag to rotate camera on Y axis and click to move to the specified ground hit position , but in the second section Update never catch MOVEMENTCLICK. But in first section its returning Collider OK debug it means its return MOVEMENTCLICK right ?
So where is the problem that i can't figure out ?
INPUT MANAGER SECTION
public ClickType OnClick()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
startClick = Input.GetKeyDown(KeyCode.Mouse0);
currentClick = Input.GetKey(KeyCode.Mouse0);
endClick = Input.GetKeyUp(KeyCode.Mouse0);
uiClick = EventSystem.current.IsPointerOverGameObject();
//if click on UI
if (startClick && uiClick)
{
return ClickType.BUTTONCLICK;
}
if (startClick)
{
isPressed = true;
currentPosition = Input.mousePosition;
currentDistance = Vector2.Distance(Input.mousePosition, currentPosition);
}
if (isPressed && currentClick)
{
currentDistance = Vector2.Distance(Input.mousePosition, currentPosition);
if(currentDistance > clickThreshold)
{
return ClickType.ROTATIONCLICK;
}
}
if(isPressed && endClick || isPressed && !currentClick)
{
isPressed = false;
if (currentDistance < clickThreshold)
{
Debug.Log("Distance OK");
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
Debug.Log("Hit OK");
if (hit.collider.gameObject.layer == 6)
{
Debug.Log("Collider OK");
return ClickType.MOVEMENTCLICK;
}
else
{
Debug.Log("Collider NOT OK");
}
}
else
{
Debug.Log("Hit NOT OK");
}
}
}
return ClickType.NOTHING;
}
PLAYER CONTROLLER SECTION
private void Update()
{
if (InputManager.Instance.OnClick() == InputManager.ClickType.MOVEMENTCLICK)
{
canMove = false;
clickMove = true;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
if (hit.collider.gameObject.layer == 6)
{
targetPos = new Vector3(hit.point.x, rb.position.y, hit.point.z);
MoveToPosition(targetPos);
}
}
}
}
Comment