Home > Mobile >  Add distance to x axis and z axis
Add distance to x axis and z axis

Time:05-02

I'm creating a pool game. What I'm planning to do is when a player adjust the slider the x-axis and z-axis should also be adjusted. Is there a function in unity that add distance or similar to that function? enter image description here

CodePudding user response:

If you are talking about a slider in the inspector then you will need to use unities "OnValidate" function which updates whenever a value changes in the inspector for that class.

If you already have that sorted and are just wondering how to make the object move along its axes, then you will want to do

SomeObject.transform.position = SomeObject.transform.left * moveLeftAmount

which will add a distance to to left direction of the vector and then

SomeObject.transform.position = SomeObject.transform.up * moveUpAmount

would do it for the Y direction. If you want it to be relative, then just keep track of where the object was with a class variable and offset it from there based on SomeObject.transform.left * distanceValue

  • Related