r2mods/ilspy_dump/ror2_csproj/RoR2/LookAtTransform.cs

58 lines
910 B
C#
Raw Normal View History

2024-10-04 07:26:37 +00:00
using System;
using UnityEngine;
namespace RoR2;
[ExecuteAlways]
public class LookAtTransform : MonoBehaviour
{
public enum Axis
{
Right,
Left,
Up,
Down,
Forward,
Backward
}
public Transform target;
public Axis axis = Axis.Forward;
private void LateUpdate()
{
if (!target)
{
return;
}
Vector3 vector = target.position - base.transform.position;
if (!(vector == Vector3.zero))
{
switch (axis)
{
case Axis.Right:
base.transform.right = vector;
break;
case Axis.Left:
base.transform.right = -vector;
break;
case Axis.Up:
base.transform.up = vector;
break;
case Axis.Down:
base.transform.right = -vector;
break;
case Axis.Forward:
base.transform.forward = vector;
break;
case Axis.Backward:
base.transform.forward = -vector;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}