Skip to content

Instantly share code, notes, and snippets.

@dyguests
Created March 6, 2021 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyguests/a98e4b74e43950c65691324243816a46 to your computer and use it in GitHub Desktop.
Save dyguests/a98e4b74e43950c65691324243816a46 to your computer and use it in GitHub Desktop.
Mouse To World
using Common;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Game
{
public class InputCtlr : MonoBehaviour
{
private InputActions inputActions;
private void Awake()
{
inputActions = new InputActions();
inputActions.Game.Tap.performed += Tap;
}
private void OnEnable()
{
inputActions.Game.Enable();
}
private void OnDisable()
{
inputActions.Game.Disable();
}
private void Tap(InputAction.CallbackContext ctx)
{
var mousePos = inputActions.Game.Position.ReadValue<Vector2>();
// Debug.Log("InputCtlr:mousePos:" + mousePos);
Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
// var ray = Camera.main.ScreenPointToRay(worldPos);
RaycastHit2D hit = Physics2D.Raycast(worldPos, Vector2.zero);
if (hit)
{
var go = hit.transform.gameObject;
if (go.CompareTag(Tags.Bubble))
{
go.GetComponent<BubbleCtlr>().Poked();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment