Skip to content

Instantly share code, notes, and snippets.

@giftheck
Created May 18, 2021 13:55
Show Gist options
  • Select an option

  • Save giftheck/108306e6b9a7f09d8512670c1acc08b2 to your computer and use it in GitHub Desktop.

Select an option

Save giftheck/108306e6b9a7f09d8512670c1acc08b2 to your computer and use it in GitHub Desktop.
Column Tales
using UnityEngine;
public class HorizontalMovementDisabler : MonoBehaviour
{
public GameObject columnObject; //Object the rotation script is attached to
public string scriptName; //The name of the script
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Environment")
{
Debug.Log("Trigger picked up an environment collision");
StopRotation();
}
else if (other.tag == "Enemy")
{
Debug.Log("Trigger picked up an enemy collision");
StopRotation();
}
else if (other.tag == "Obstacle")
{
Debug.Log("Trigger picked up an obstacle collision");
StopRotation();
}
else
{
Debug.Log("Trigger did not pick up a collision that needed to be detected");
StartRotation();
}
}
private void OnTriggerExit(Collider other)
{
Debug.Log("Object exited the trigger, rotation restarted");
StartRotation();
}
private void StopRotation()
{
(columnObject.GetComponent(scriptName) as MonoBehaviour).enabled = false;
}
private void StartRotation()
{
(columnObject.GetComponent(scriptName) as MonoBehaviour).enabled = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment