The player in my game has 2000 health, I have a red vignette that appears when your health is low but I cannot get it to work.
I want it to be reliable so I’m trying to make it the vignette intensity scale up when the health goes down.
private void OnTriggerEnter(Collider other)
{
if ( other.GetComponent<Damage>() )
{
health -= other.GetComponent<Damage>().damage;
Debug.Log(65 / health); // Returns 0
vg.intensity.value = 1 / health * vignetteMultiplier;
Debug.Log(vg.intensity.value); // Also returns 0
}
}
}
And I know I do change the vignette intensity because if I set it to be 1 in the script it does change.
(Full script, in case anyone wants it)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using DG.Tweening;
using UnityEngine.SceneManagement;
public class Player : MonoBehaviour
{
public int health = 2000;
public MeshRenderer whiteScreen;
public Volume v;
public float vignetteMultiplier = 65f;
private Vignette vg;
private void Start()
{
v.profile.TryGet(out vg);
whiteScreen.material.DOFade(0, 3);
}
private void Update()
{
if ( Inputs.aButtonPressed )
{
Time.timeScale = 0.05f;
Time.fixedDeltaTime = 0.002f;
foreach ( AudioSource audio in FindObjectsOfType<AudioSource>() )
{
audio.pitch = 0.5f;
}
}
else
{
Time.timeScale = 1f;
Time.fixedDeltaTime = 0.02f;
foreach ( AudioSource audio in FindObjectsOfType<AudioSource>() )
{
audio.pitch = 1;
}
}
if ( health < 1 )
{
StartCoroutine(LoadMainMenu());
}
}
private void OnTriggerEnter(Collider other)
{
if ( other.GetComponent<Damage>() )
{
health -= other.GetComponent<Damage>().damage;
Debug.Log(65 / health); // Returns 0
vg.intensity.value = 1 / health * vignetteMultiplier;
Debug.Log(vg.intensity.value); // Also returns 0
}
}
IEnumerator LoadMainMenu()
{
whiteScreen.material.DOFade(255, 5);
yield return new WaitForSeconds(6);
SceneManager.LoadScene("Main Menu");
}
}