Hi anyone reading this. Hope you’re having a good day. I am very much a beginner, who has only recently passed the phase of having to follow a step by step tutorial. I run into issues every five minutes, but still. Basically, I am trying to work on a small top-down parkour game where the player jumps between colourful towers. Naturally, the idea of top-down parkour is flawed because of depth perception meaning you have little way of telling how far from the ground you are. Knowing this, I would like to implement a system which darkens these towers the higher above the towers the player is. Meaning that as the player falls, the tower should become brighter, until they land on it, at which point it is just a normal, fully bright object. I thought that the best way to implement this would be a class, which, it doesn’t take a genius to figure out is terrible code (PS. This wasn’t complete):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MaterialChange : MonoBehaviour
{
public Material tower1Material;
public Material tower2Material;
public Material tower3Material;
public Material tower4Material;
public Material tower5Material;
public Material tower6Material;
public Material tower7Material;
public Material tower8Material;
public Material tower9Material;
public Material tower10Material;
public Color tower1Color;
public Color tower2Color;
public Color tower3Color;
public Color tower4Color;
public Color tower5Color;
public Color tower6Color;
public Color tower7Color;
public Color tower8Color;
public Color tower9Color;
public Color tower10Color;
public class EnvironmentHeight
{
public float tower1;
public float tower2;
public float tower3;
public float tower4;
public float tower5;
public float tower6;
public float tower7;
public float tower8;
public float tower9;
public float tower10;
public EnvironmentHeight(float firstTower, float secondTower,
float thirdTower, float fourthTower,
float fifthTower, float sixthTower,
float seventhTower, float eighthTower,
float ninthTower, float tenthTower)
{
tower1 = firstTower;
tower2 = secondTower;
tower3 = thirdTower;
tower4 = fourthTower;
tower5 = fifthTower;
tower6 = sixthTower;
tower7 = seventhTower;
tower8 = eighthTower;
tower9 = ninthTower;
tower10 = tenthTower;
}
}
void Start()
{
EnvironmentHeight level1EnvironmentHeights = new EnvironmentHeight(0f, 0f, 0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
}
// Update is called once per frame
void Update()
{
BrightnessChange();
}
void BrightnessChange()
{
PlayerMovement playerMovementCall = new PlayerMovement();
float verticalPlayerPosition = playerMovementCall.publicCharacterYPosition;
tower1Color.r = verticalPlayerPosition / 10;
}
}
As you can probably guess, I have doubts about this code. In case you’re wondering, I was going to instantiate the class for every new level with 10 variables, each with the height of the towers. Also, each tower was going to be a different colour, which is why I made 10 material reference variables.
Is there any way to make this system work without cluttering code with ten of each variable ( ten was going to be the maximum amount of towers that a level would have, which would be another thing that would be good to not have the restriction of.) I hope I gave enough detail. Thanks for reading.