Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Test : MonoBehaviour
- {
- [SerializeField]
- private Camera Camera;
- Collider col;
- public GameObject crosshair;
- Image image;
- private void OnValidate()
- {
- if (Camera == null)
- amera = Camera.main;
- }
- // Start is called before the first frame update
- void Start()
- {
- crosshair.SetActive(false);
- col = GetComponent<Collider>();
- image = gameObject.GetComponent<Image>();
- }
- // Update is called once per frame
- void Update()
- {
- Vector3 mouseScreenPosition = Input.mousePosition;
- Ray ray = GetComponent<Camera>().ScreenPointToRay(mouseScreenPosition);
- if (Input.GetMouseButtonDown(0))
- {
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit))
- {
- crosshair.SetActive(true);
- print("getroffen");
- }
- if (col.gameObject.tag == "Enemy")
- {
- Destroy(gameObject);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement