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.EventSystems;
- public class DestroyOnRClick : MonoBehaviour
- {
- Ray ray;
- RaycastHit2D hit;
- public int hits_needed;
- // Start is called before the first frame update
- void Start()
- {
- //this.hits_needed = hits_needed;
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetMouseButton(1))
- {
- RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
- //Ray ray;
- //RaycastHit2D hit;
- if (hit.collider != null)
- {
- if (hit.collider.gameObject.name != "grass")
- {
- if ((hit.collider.gameObject.tag == "grass") || (hit.collider.gameObject.tag == "block"))
- {
- //Debug.Log("Hit grass object.");
- hits_needed -= 1;
- if (hits_needed <= 0)
- {
- Destroy(collider.gameObject);
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement