Created
March 6, 2021 13:47
-
-
Save dyguests/a98e4b74e43950c65691324243816a46 to your computer and use it in GitHub Desktop.
Mouse To World
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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