Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Test : MonoBehaviour
  7. {
  8.     [SerializeField]
  9.     private Camera Camera;
  10.  
  11.     Collider col;
  12.  
  13.     public GameObject crosshair;
  14.  
  15.     Image image;
  16.  
  17.  
  18.     private void OnValidate()
  19.     {
  20.         if (Camera == null)
  21.             amera = Camera.main;
  22.     }
  23.  
  24.     // Start is called before the first frame update
  25.     void Start()
  26.     {
  27.         crosshair.SetActive(false);
  28.         col = GetComponent<Collider>();
  29.         image = gameObject.GetComponent<Image>();
  30.  
  31.     }
  32.  
  33.     // Update is called once per frame
  34.     void Update()
  35.     {
  36.         Vector3 mouseScreenPosition = Input.mousePosition;
  37.  
  38.  
  39.  
  40.         Ray ray = GetComponent<Camera>().ScreenPointToRay(mouseScreenPosition);
  41.  
  42.         if (Input.GetMouseButtonDown(0))
  43.         {
  44.             RaycastHit hit;
  45.            
  46.  
  47.             if (Physics.Raycast(ray, out hit))
  48.             {
  49.                
  50.                
  51.                     crosshair.SetActive(true);
  52.                     print("getroffen");
  53.                
  54.             }
  55.             if (col.gameObject.tag == "Enemy")
  56.             {
  57.                 Destroy(gameObject);
  58.             }
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement