vendredi 31 mai 2019

How would you change multiple variables to false if their individual values are zero?

Context:

I'm working on a game in Unity and I have a piece of code which you can make destroy an object after it reaches or passes a certain point in the x or y-axes or after a set amount of time. In the script, I have a few safeguards for incorrectly filling out what values of time, x and y coordinates you would like the object to be destroyed at.

Quick Data Dictionary:

killPosX, float

killPosY, float

killPosT, float

killX, boolean

killY, boolean

killT, boolean

Code:

I would like to make my code a little more compact. Here is the original.

if (killPosX != 0) //x position you would like the object to be destroyed at
{
    killX = true; //make sure the value is set to true
}

if (killPosY != 0) //y position you would like the object to be destroyed at
{
    killY = true; //make sure the value is set to true
}

if (killPosT != 0) //position in time you would like the object to be destroyed at
{
    killT = true; //make sure the value is set to true
}

Is there some way in C# to turn this piece of code into something that might look like this:

if ([killPosX, killPosY, killPosT] != 0)
{
    [killPosX, killPosY, killPosT] = true;
}

Where the code would check if each value in the array [killPosX, killPosY, killPosT] were not equal to 0 individually (or something which would get the same job done)?

Aucun commentaire:

Enregistrer un commentaire