Initial commit
This commit is contained in:
26
Assets/Scripts/CanvasFollowPlanet.cs
Normal file
26
Assets/Scripts/CanvasFollowPlanet.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CanvasFollowPlanet : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform planet;
|
||||
[SerializeField] private Vector3 worldOffset = new Vector3(0, 5, 0);
|
||||
[SerializeField] private Camera mainCamera;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (mainCamera == null)
|
||||
mainCamera = Camera.main;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (mainCamera == null || planet == null) return;
|
||||
|
||||
transform.position = planet.position + worldOffset;
|
||||
|
||||
Vector3 lookDirection = mainCamera.transform.position - transform.position;
|
||||
transform.rotation = Quaternion.LookRotation(-lookDirection, Vector3.up);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user