New Unity Input System Touch Controls - Destroying GameObjects On Mobile

Here’s the issue: I wanna destroy gameobjects after I “discover” them.

What I Have Done: I put an interactables script on my object that sets FX active when the player gets close and collides with a trigger. I wanted to use a raycast on the screen so that the player can tap on the object and collect it. I’d like to destroy the object before adding it as a variable to inventory.

Raycasting: I’ve researched raycasting and, after throwing a raycast on my camera, I was able to trigger raycasts (using debug.log and debug.drawray), but I don’t know how to connect raycasts to the new Unity input system’s touch stuff. On top of that, my cubes aren’t recognizing the raycasts either when I used the “OnColliderEnter” method. I haven’t yet found a YT tutorial that explains how to connect raycasts from one script to triggers and scripts on another separate gameobject. On top of that, all of the YT videos I’ve seen so far just show how to use the new input system for movement, etc, using gamepad/keyboards, but none really talk about destroying gameobjects. Any tips?

-curious hobbyist

----> the script that I have been using so far (Samyam script)
—> you can see that at the bottom, I was trying out the inputtouch stuff, but obviously it isn’t working because I must either be using the old system or I’m not connecting it properly to the new input touch system… v.v
Thank you in advance for any help!

using UnityEngine; public class PlayerController : MonoBehaviour {

private PlayerInputControls playerInput;
private Transform cameraMain;
private Transform child;
private CharacterController controller;
private Vector3 playerVelocity;
private bool groundedPlayer;

[SerializeField] private float playerSpeed = 2.0f;
[SerializeField] private float jumpHeight = 1.0f;
[SerializeField] private float gravityValue = -9.81f;
[SerializeField] private float rotationSpeed = 4f;

private void Awake()
    playerInput = new PlayerInputControls();
    controller = GetComponent<CharacterController>();

private void OnEnable()

private void OnDisable()

private void Start()
    cameraMain = Camera.main.transform;
    child = transform.GetChild(0).transform;      

void Update()
    //moving & jumping
    groundedPlayer = controller.isGrounded;
    if (groundedPlayer && playerVelocity.y < 0)
        playerVelocity.y = 0f;

    Vector2 movementInput = playerInput.PlayerMain.Move.ReadValue<Vector2>();
    Vector3 move = (cameraMain.forward * movementInput.y + cameraMain.right * movementInput.x);
    move.y = 0f;
    controller.Move(move * Time.deltaTime * playerSpeed);

    // Changes the height position of the player..
    if (playerInput.PlayerMain.Jump.triggered && groundedPlayer)
        playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
        Debug.Log("Space is pressed");

    playerVelocity.y += gravityValue * Time.deltaTime;
    controller.Move(playerVelocity * Time.deltaTime);

    if (movementInput !=
        Quaternion rotation = Quaternion.Euler(new Vector3(child.localEulerAngles.x, cameraMain.localEulerAngles.y, child.localEulerAngles.z));
        child.rotation = Quaternion.Lerp(child.rotation, rotation, Time.deltaTime * rotationSpeed);

    if ((Input.touchCount > 0) && (Input.GetTouch(0).phase == TouchPhase.Began))
        Ray raycast = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
        RaycastHit raycastHit;

        if (Physics.Raycast(raycast, out raycastHit))
            Debug.Log("Something hit");
} }

Hi ,

If you want use “OnCollisionEnter()”, “OnTriggerEnter()” or “Ray” etc. you should add Collider and Rigidbody components to your gameobjects.

(Add one Rigidbody Component enough)