Haha, I like your sense of humor. And you were right about the horrifying death camera, haha. Btw I really admire people like you who can just fix these kinds of things. I wish I had those skills.
I actually have one more issue I can’t figure out. Could you give me some pointers?
I created a blur effect through the global volume (render settings of the pipeline I’m using) and the blur effect only gets triggered when the enemy is in the chasing state. With other words, when it sees the player/when the player steps within its chasing range. I created a variable of type bool ‘enemyIsChasing’ in the EnemyStateMachine. Then in the EnemyChasingState’s Enter() method I set the variable to true, and in it’s exit method I set it to false. Then I got a script on the global volume to handle changes to the blur effect, called BlurEffectOnTargeting. This is it’s script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HauntedPSX.RenderPipelines.PSX.Runtime;
using UnityEngine.Rendering;
public class BlurEffectOnTargeting : MonoBehaviour
{
private EnemyStateMachine enemyStateMachine;
private EnemyStateMachine[] enemyStateMachines;
public Volume volume;
public float speed = 10f;
private AccumulationMotionBlurVolume _motionBlurComponent;
private float _timer;
private void Awake()
{
volume = GetComponent<Volume>();
volume.sharedProfile.TryGet(out _motionBlurComponent);
_motionBlurComponent.weight.value = 0;
enemyStateMachines = FindObjectsOfType<EnemyStateMachine>();
//EnemyStateMachine[] enemyStateMachines = FindObjectsOfType<EnemyStateMachine>();
}
private void Update()
{
foreach (EnemyStateMachine enemyStateMachine in enemyStateMachines)
{
if(enemyStateMachine.enemyIsChasing == true)
{
//_motionBlurComponent.weight.value = Mathf.PingPong(_timer * speed, 1);
_motionBlurComponent.weight.value = 0.7f;
_timer += Time.deltaTime;
}
if(enemyStateMachine.enemyIsChasing == false)
{
_motionBlurComponent.weight.value = 0f;
}
}
}
}
Now, what I think I did is in the Awake state, find ANY gameobject that has the EnemyStateMachine component on it. And then in the update state I have a foreach loop checking if there is an object with this EnemyStateMachine on it in the scene, if so, set the enemyIsChasing bool to true and active the blur effect.
IT WORKS, but… it only works on the first enemy in the scene. It doesn’t seem to get triggered for the other enemies in the scene even though they have exactly the same components on them.
What could be the reason?
I understand if you don’t want to answer since its outside the scope of the course… but I thought I’d add to it to make it more of my own thing… Cant figure out why the code won’t run… If I disable the first enemy, it works on the other enemy… but always just on 1 enemy in the scene when I press play.
Thanks!