Advertisement
salahzar

MyCollisionDetector.cs

Feb 16th, 2021
1,199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class MyCollisionDetector : MonoBehaviour
  7. {
  8.     public GameObject panel;
  9.     public Transform playerObject;
  10.    
  11.     public float distance = 2;
  12.     // Start is called before the first frame update
  13.     void Start()
  14.     {
  15.  
  16.     }
  17.    
  18.     // Update is called once per frame
  19.     void Update()
  20.     {
  21.         //Debug.LogError("Hello");
  22.     }
  23.     void OnMouseDown()
  24.     {
  25.         var dist = Math.Abs(Vector3.Distance(this.transform.position, playerObject.position));
  26.         Debug.Log("Distance is " + dist);
  27.  
  28.         if (dist < distance){
  29.             Destroy(gameObject);
  30.             panel.SetActive(true);
  31.             var conteggio = GameObject.Find("Player").GetComponent<Conteggio>();
  32.             conteggio.checkObjects();
  33.         }
  34.     }
  35.    
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement