2themoon/Assets/Scripts/CameraFollower.cs
2023-01-23 13:49:56 +05:30

45 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollower : MonoBehaviour
{
public static CameraFollower instance;
void Awake(){
instance = this;
}
public float Xsmoothness =1f;
public float Ysmoothness =1f;
public static Transform Target;
public Vector2 offset;
public Vector3 shakeIntensity;
public GameObject shakeFX_good;
public GameObject shakeFX_bad;
void FixedUpdate()
{
UpdateFrame();
}
public static void UpdateFrame(){
instance.updateFrame();
}
void updateFrame(){
float newX = Mathf.Lerp(transform.position.x, Target.position.x + offset.x, Xsmoothness);
float newY = Mathf.Lerp(transform.position.y, Target.position.y + offset.y, Ysmoothness);
transform.position = new Vector3(newX, newY, transform.position.z);
if(PlayerController.boosting){
//Add boost here
shakeFX_good.SetActive(PlayerController.instance.isUp);
shakeFX_bad.SetActive(!PlayerController.instance.isUp);
transform.position += new Vector3(Random.Range(-shakeIntensity.x, shakeIntensity.x), Random.Range(-shakeIntensity.y,shakeIntensity.y), Random.Range(-shakeIntensity.z,shakeIntensity.z));
}else{
shakeFX_good.SetActive(false);
shakeFX_bad.SetActive(false);
}
}
}