hello, trying to keep my code short i come across this question
How can i convert the interaction mode into an int value?
For example if(Physics.SphereCast(origin,radius,…,Physics.AllLayers, QueryTriggerInteraction.Collide)){…}, instead of writting “QueryTriggerInteraction.Collide” i want to write “2”. Beside 0, 1 and 2 arent recognized.
The simple fix would be to cast 2 to a QueryTriggerInteraction so that the compiler treats 2 as a QueryTriggerInteraction.
if(Physics.SphereCast(origin,radius,........,Physics.AllLayers, (QueryTriggerInteraction)2))
As you can see, this doesn’t make the code much shorter. So there is no real “fix”.
The thing is, although your code seems longer with longer words, it does not become functionally longer to the computer. QueryTriggerInteraction.Collide
takes almost the same processing power as just 2
, even though it takes more time to type. And casting (QueryTriggerInteraction)2
might actually take more power, I’m not entirely sure. So my advice is to keep QueryTriggerInteraction.Collide
because it’s easier for humans to understand and equivalent for computers.