Advertisement
johnnygoodguy2000

PlatformDestroyer.cs

Apr 7th, 2024 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlatformDestroyer : MonoBehaviour
  6. {
  7.     // This variable will store a reference to the GameObject itself
  8.     public GameObject platformDestructionPoint;
  9.  
  10.     // Start is called before the first frame update
  11.     void Start()
  12.     {
  13.         // Instead of using GameObject.Find, simply assign the GameObject to the variable
  14.         platformDestructionPoint = this.gameObject;
  15.  
  16.         // Check if the GameObject reference is null (This is less likely to happen now)
  17.         if (platformDestructionPoint == null)
  18.         {
  19.             Debug.LogWarning("PlatformDestructionPoint reference is null.");
  20.         }
  21.     }
  22.  
  23.     // Update is called once per frame
  24.     void Update()
  25.     {
  26.         // Check if the PlatformDestructionPoint GameObject is found before accessing its position
  27.         if (platformDestructionPoint != null && transform.position.x < platformDestructionPoint.transform.position.x)
  28.         {
  29.             // Disable the GameObject instead of destroying it
  30.             gameObject.SetActive(false);
  31.         }
  32.     }
  33. }
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement