Skip to content

Instantly share code, notes, and snippets.

@AmmarTee
Created December 19, 2022 07:39
Show Gist options
  • Save AmmarTee/0861559b0c5219ec86832a175c7b615a to your computer and use it in GitHub Desktop.
Save AmmarTee/0861559b0c5219ec86832a175c7b615a to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyIf : MonoBehaviour
{
// Start is called before the first frame update
// OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
// OnTriggerEnter is called when the Collider other enters the trigger.
public Transform player;
// Awake is called when the script instance is being loaded.
protected void Awake()
{
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
}
// Update is called every frame, if the MonoBehaviour is enabled.
protected void LateUpdate()
{
if(this.transform.position.z<player.transform.position.z-2)
{
Destroy(this.gameObject);
}
}
protected void OnTriggerEnter(Collider other)
{
if(other.gameObject.CompareTag("Fire"))
{
Destroy(this.gameObject);
}
if(this.gameObject.CompareTag("Blue") && other.gameObject.CompareTag("Player"))
{
Destroy(this.gameObject);
}
if(this.gameObject.CompareTag("Red") && other.gameObject.CompareTag("Player"))
{
PlayerController.instance.isEnd = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment