Question by
imagio1 · Mar 05, 2017 at 07:32 PM ·
axestransforms
Can I use the axis name as a variable?
I am building an app that has a lot of geometry involved. I find that the my code has a lot of code lines tripled, since I am repeating each command for x, y and z axes. If I could find a way to use the axis name (x,y,z) in transform properties, that would make my code much cleaner. e.g:
GameObject myObj;
float getPositionOnAxis (string axisName){
return myObj.transform.position[axisName];
}
Is there a way to achieve that? In some cases I can use Vector.up etc (e.g on Rotate function), but how can it help me with the example above?
Comment