Advertisement
jamieTheCoder

MousePosition3D

Sep 23rd, 2022 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using MoreMountains.Tools;
  5.  
  6. public class MousePosition3D : MonoBehaviour
  7. {
  8.     [SerializeField] private Camera  mainCamera;
  9.     [SerializeField] private LayerMask WhatIsGround;
  10.     [SerializeField] private float Range;
  11.     [SerializeField]private GameObject playerObj;
  12.     private WebMovement webMovement;
  13.     // Start is called on the frame when a script is enabled just before any of the Update methods is called the first time.
  14.     private void Start()
  15.     {
  16.         webMovement = GetComponent<WebMovement>();
  17.         Invoke("GetGameObjectWithMethod",2f);
  18.     }
  19.     private void Update()
  20.     {
  21.         Ray ray = mainCamera.ScreenPointToRay(new Vector3(Input.mousePosition.x,Input.mousePosition.y,0f));
  22.         if(Physics.Raycast(ray, out RaycastHit raycastHit,WhatIsGround))
  23.         {
  24.             transform.position = raycastHit.point;
  25.         }
  26.     }
  27.     public void GetGameObjectWithMethod()
  28.     {
  29.         playerObj = GameObject.FindGameObjectWithTag("Player");
  30.         webMovement.playerObj = playerObj;
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement