Using a Boolean Logical Operator
Currently if a Player is flying into an item it will always collect it. But that’s not really what we want, instead we’d like the Player only to be able to pick up the item once and only when it’s allowed. So for example we don’t want to execute the health Power up logic if the Player is already full health. To fix that we could create a Boolean Logical Operator in the Player.cs Script and create a reference to it in the Item.cs Script.
Short for boolean, a ‘bool’ type is a data type that can only return one of two values, true or false. The bool type is the result type of comparison and equality operators and false by default. It can be used for controlling conditional expressions.
Applied to our Players.cs Script;
If our current health is equal to our max. health, we return false and else we return true.
However since the default value of the type bool is false we can shorten it down declaring; result is always false and return true if current health is less than our max. health.
Now that we have a method to check if the Player is full health or not, we can call this method in the Item.cs Script and only allow a health power up to be picked up when the Player is not full health.