So, I’m trying to make a game the idea is basically a platformer that can change color on a certain key press, and you have basic platforms with different colors, the player can switch colors in air to match the next platform color, if the color doesn’t match, you fail!.
So, I’ll write a script to assign this two materials to platforms randomly by using an array, once this is done I’ll write a script that enables player to change the color, so what I basically need help for is how do I check if the player and the platform materials match, should I edit the script to assign a tag to the platform based on the material assigned to it, remember I’m assigning materials randomly through script, I’m open for opinions
What I would do is create a public enum class that holds all of your colors, e.g., Colors.Red
, Colors.Green
. Then you can create a variable in each script of the type of your enum, and using that you can check against other Actors:
public Colors MyColor = Colors.Green;
if (PlatformActor.As<PlatformScript>().MyColor == this.MyColor)
{
// Do something
}
else
{
// Do something else
}
You can also set the material color of the Actors based on their MyColor variable using a switch statement. I hope this is what you were hoping to know.
1 Like