Created
May 1, 2019 03:01
-
-
Save SenpaiRar/f369aa2663297ba38bef28da306cb97c to your computer and use it in GitHub Desktop.
How the game handles the player clicking on the screen
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Player_Cursor : MonoBehaviour { | |
public Camera main_Camera; | |
public GameObject Player; | |
// Update is called once per frame | |
void Start(){ | |
Cursor.visible = true; By default, the player can't see their cursor. So we just make it visible. | |
} | |
void Update () { | |
ClickOn(); | |
} | |
void ClickOn() | |
{ | |
if (Input.GetMouseButtonUp(1)) | |
{ | |
Ray camera_Ray = main_Camera.ScreenPointToRay(Input.mousePosition); | |
RaycastHit hit_Ray; | |
Physics.Raycast(camera_Ray, out hit_Ray); | |
ClickableParent C = hit_Ray.collider.gameObject.GetComponent(); | |
C.OnClick(Player.transform.position); | |
} | |
} | |
public static Vector3 GetPositionClick(Camera C) //returns the point where the raycast hit on the ground | |
{ | |
Ray camera_Ray = C.ScreenPointToRay(Input.mousePosition); | |
RaycastHit hit; | |
Physics.Raycast(camera_Ray, out hit); | |
return (hit.point); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment