Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to change mousePosition

Discussion in 'Scripting' started by Lex_212, Dec 28, 2021.

  1. Lex_212

    Lex_212

    Joined:
    Oct 3, 2020
    Posts:
    84
    Hi, while watching a video about interactables objects, they used the mousePosition to detect if an object is interactable or nor, but in my game the mouse is not visible and does not have an use. Does anybody know how to change it so it does not use the mousePosition?
    This is the code:
    Code (CSharp):
    1. if(Input.GetButton("Horizontal"))
    2.         {
    3.             // We create a ray
    4.             Ray ray = camRay.ScreenPointToRay(Input.mousePosition);
    5.             RaycastHit hit;
    6.  
    7.             // If the ray hits
    8.             if (Physics.Raycast(ray, out hit, 100))
    9.             {
    10.                 Interactable interactable = hit.collider.GetComponent<Interactable>();
    11.                 if (interactable != null)
    12.                 {
    13.                     SetFocus(interactable);
    14.                 }
    15.             }
    16.         }
     
    CTN-Originals likes this.
  2. CTN-Originals

    CTN-Originals

    Joined:
    May 30, 2020
    Posts:
    6