I posted this in unity answers and got no responses sooo
An example of the layers changing is when the camera shakes, my gun goes infront of my player even though it was behind it before, and overlapping platforms change layer too, like the floor appeared infront of the wall before but during the shake sometimes it goes behind it. When the camera stops shaking, the layers are back to normal btw. Here’s my code:
using System.Threading;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class CameraShake : MonoBehaviour
{
public static CameraShake Instance { get; private set;}
private CinemachineVirtualCamera cam;
private float shakeTimer;
void Awake()
{
Instance = this;
cam = GetComponent<CinemachineVirtualCamera>();
}
public void Shake(float intensity, float time){
CinemachineBasicMultiChannelPerlin camPerlin = cam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
camPerlin.m_AmplitudeGain = intensity;
shakeTimer = time;
}
private void Update()
{
if(shakeTimer>0){
shakeTimer -= Time.deltaTime;
if (shakeTimer <=0f){
CinemachineBasicMultiChannelPerlin camPerlin = cam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
camPerlin.m_AmplitudeGain = 0f;
}
}
}
}
I didn’t use the shake extension for cinemachine btw