Make progress bar face camera with custom script

This commit is contained in:
BuyMyMojo 2023-03-01 04:19:40 +11:00
parent 4ad7bf281c
commit af6a45633b
4 changed files with 64 additions and 1 deletions

View file

@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LookAtCamera : MonoBehaviour
{
private enum Mode
{
LookAt,
LookAtInverted,
CameraForward,
CameraForwardInverted,
}
[SerializeField] private Mode mode;
private void LateUpdate()
{
switch (mode)
{
case Mode.LookAt:
transform.LookAt(Camera.main.transform);
break;
case Mode.LookAtInverted:
Vector3 dirFromCamera = transform.position - Camera.main.transform.position;
transform.LookAt(transform.position + dirFromCamera);
break;
case Mode.CameraForward:
transform.forward = Camera.main.transform.forward;
break;
case Mode.CameraForwardInverted:
transform.forward = -Camera.main.transform.forward;
break;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5808323afc086764e9ce5b8db2df4456
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: