daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 72 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.  
  6. public class DestroyOnRClick : MonoBehaviour
  7. {
  8.     Ray ray;
  9.     RaycastHit2D hit;
  10.  
  11.     public int hits_needed;
  12.  
  13.     // Start is called before the first frame update
  14.     void Start()
  15.     {
  16.         //this.hits_needed = hits_needed;
  17.     }
  18.  
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.         if (Input.GetMouseButton(1))
  23.         {
  24.             RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
  25.             //Ray ray;
  26.             //RaycastHit2D hit;
  27.  
  28.             if (hit.collider != null)
  29.             {
  30.                 if (hit.collider.gameObject.name != "grass")
  31.                 {
  32.                     if ((hit.collider.gameObject.tag == "grass") || (hit.collider.gameObject.tag == "block"))
  33.                     {
  34.  
  35.                         //Debug.Log("Hit grass object.");
  36.                         hits_needed -= 1;
  37.                         if (hits_needed <= 0)
  38.                         {
  39.                             Destroy(collider.gameObject);
  40.                         }
  41.  
  42.                     }
  43.                 }
  44.             }
  45.         }  
  46.     }
  47. }
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