Created
March 2, 2025 03:21
-
-
Save lamarmarshall/53837accaaa4c971d54306e3a6a1ef60 to your computer and use it in GitHub Desktop.
unity, touch screen
This file contains hidden or 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 UnityEngine; | |
using UnityEngine.InputSystem; | |
public class BallHandler : MonoBehaviour | |
{ | |
private Camera mainCamera; | |
// Start is called once before the first execution of Update after the MonoBehaviour is created | |
void Start() | |
{ | |
mainCamera = Camera.main; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
if(!Touchscreen.current.primaryTouch.press.isPressed) | |
{ | |
return; | |
} | |
Vector2 touchPos = Touchscreen.current.primaryTouch.position.ReadValue(); | |
Vector3 worldPos = mainCamera.ScreenToWorldPoint(touchPos); | |
Debug.Log(touchPos); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment