ソースコード
using UnityEngine;
<summary>
</summary>
public static class GameObjectExtensions
{
<summary>
</summary>
public static void LookAt(this GameObject self, GameObject target)
{
self.transform.LookAt(target.transform);
}
<summary>
</summary>
public static void LookAt(this GameObject self, Transform target)
{
self.transform.LookAt(target);
}
<summary>
</summary>
public static void LookAt(this GameObject self, Vector3 worldPosition)
{
self.transform.LookAt(worldPosition);
}
<summary>
</summary>
public static void LookAt(this GameObject self, GameObject target, Vector3 worldUp)
{
self.transform.LookAt(target.transform, worldUp);
}
<summary>
</summary>
public static void LookAt(this GameObject self, Transform target, Vector3 worldUp)
{
self.transform.LookAt(target, worldUp);
}
<summary>
</summary>
public static void LookAt(this GameObject self, Vector3 worldPosition, Vector3 worldUp)
{
self.transform.LookAt(worldPosition, worldUp);
}
}
使い方
gameObject.LookAt(target);
関連記事