Gameplay.DestroyByLava - robblofield/TomeboundDocs GitHub Wiki
Gameplay.DestroyByLava
Author: Shahrzad Beevis
Last Updated: 04/12/2023
Overview
A simple script that destroys the GameObject it is attached to if it comes in contact with lava.
Dependencies
N/A
Contents
- Use case
- Breakdown of code
- Using Statements
- Class Declaration
- Method/OnTriggerEnter(Collider other)
- Future Expansion
- Full Code Reference
Use case
This script is currently being used on any object that is destroyed by lava when interacting with it - e.g. enemy's, crates, water buckets etc.
Breakdown of Code
Using Statements
using UnityEngine;
Class Declaration
public class DestroyByLava : MonoBehaviour
OnTriggerEnter(Collider other)
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Lava"))
{
gameObject.SetActive(false);
}
}
}}
This method is automatically called when a collider enters the trigger zone of the GameObject it is attached to. It checks whether the GameObject that entered the trigger zone has the tag "Lava". If the entering GameObject does have the tag "Lava", GameObject to which this script is attached is deactivated.
Future Expansion
N/A
Full Code Reference
using UnityEngine;
public class DestroyByLava : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Lava"))
{
gameObject.SetActive(false);
}
}
}