You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
864 B
C#
39 lines
864 B
C#
using UnityEngine;
|
|
|
|
namespace MalbersAnimations
|
|
{
|
|
[AddComponentMenu("Malbers/Utilities/Tools/Gravity Changer")]
|
|
|
|
public class GravityChanger : MonoBehaviour
|
|
{
|
|
IGravity animal;
|
|
protected Collider Other;
|
|
void OnTriggerEnter(Collider other)
|
|
{
|
|
Other = other;
|
|
animal = other.GetComponentInParent<IGravity>();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (animal != null)
|
|
{
|
|
animal.Gravity = (transform.position - Other.transform.position).normalized;
|
|
}
|
|
}
|
|
|
|
|
|
void OnTriggerExit(Collider other)
|
|
{
|
|
ResetAnimal();
|
|
}
|
|
|
|
public virtual void ResetAnimal()
|
|
{
|
|
if (animal != null) animal.Gravity = Vector3.down;
|
|
|
|
animal = null;
|
|
Other = null;
|
|
}
|
|
}
|
|
} |