Hi, I’m currently dealing with something that’s mostly figured out, but the opposite of what I want is occurring.
What I’m trying to do is that when an object above the player is approaching more closely, the screen gets darker for a claustrophobic feel. What’s happening instead is that when the object gets further away, the screen gets darker; and if the object gets closer, the screen gets brighter. How would I reverse this effect?
Also, sorry if the code isn’t elegant; still learning C#. Thank you!
void Crushed()
{
///Create a screen-darken effect around the borders if the player is close to being crushed.
RaycastHit2D hitUpRange = new RaycastHit2D();
hitUpRange = Physics2D.Raycast(transform.position, Vector2.up, crushRangeMax, whatIsHexPlate);
RaycastHit2D hitDownRange = new RaycastHit2D();
hitDownRange = Physics2D.Raycast(transform.position, Vector2.down, crushRangeMax, whatIsHexPlate);
if ((hitUpRange.collider != null && hitUpRange.collider.tag == "HexPlate") && (hitDownRange.collider != null && hitDownRange.collider.tag == "HexPlate"))
{
isInCrushRange = true;
other = hitUpRange.collider.transform;
float crushRangeDistance = Vector2.Distance(other.position, transform.position);
gradientColor = new Color(0f, 0f, 0f, (crushRangeDistance * .1f));
}
else
{
isInCrushRange = false;
}
if (isInCrushRange)
{
crushImage.color = gradientColor;
}
else
{
crushImage.color = new Color(0f, 0f, 0f, 0f);
}