Skip to content

Instantly share code, notes, and snippets.

@lamarmarshall
Created March 2, 2025 03:21
Show Gist options
  • Save lamarmarshall/53837accaaa4c971d54306e3a6a1ef60 to your computer and use it in GitHub Desktop.
Save lamarmarshall/53837accaaa4c971d54306e3a6a1ef60 to your computer and use it in GitHub Desktop.
unity, touch screen
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