SHARE
TWEET

Untitled

a guest Jul 19th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using Devdog.General2;
  6.  
  7. namespace Grendelbiter
  8. {
  9.  
  10.     public class SetTarget : MonoBehaviour, IPlayerInputCallbacks
  11.     {
  12.         [SerializeField] private GameObject Target;
  13.  
  14.         private void Update()
  15.         {
  16.             if (Input.GetButton("Fire1"))
  17.             {
  18.                 TargetSet();
  19.             }
  20.         }
  21.  
  22.         public virtual void SetInputActive(bool val)
  23.         {
  24.             enabled = val;
  25.         }
  26.  
  27.         private void TargetSet()
  28.         {
  29.             if (!EventSystem.current.IsPointerOverGameObject() && enabled)
  30.             {
  31.                 RaycastHit hit;
  32.                 Ray ray;
  33.                 ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  34.                 int layerMask = 1 << 8;
  35.                 if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
  36.                 {
  37.                     Target.transform.position = hit.point;
  38.                 }
  39.             }
  40.         }
  41.  
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top