Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlatformDestroyer : MonoBehaviour
- {
- // This variable will store a reference to the GameObject itself
- public GameObject platformDestructionPoint;
- // Start is called before the first frame update
- void Start()
- {
- // Instead of using GameObject.Find, simply assign the GameObject to the variable
- platformDestructionPoint = this.gameObject;
- // Check if the GameObject reference is null (This is less likely to happen now)
- if (platformDestructionPoint == null)
- {
- Debug.LogWarning("PlatformDestructionPoint reference is null.");
- }
- }
- // Update is called once per frame
- void Update()
- {
- // Check if the PlatformDestructionPoint GameObject is found before accessing its position
- if (platformDestructionPoint != null && transform.position.x < platformDestructionPoint.transform.position.x)
- {
- // Disable the GameObject instead of destroying it
- gameObject.SetActive(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement