I’m trying to create a kind of slot (but not a slot machine). I created an animated object that is started and stopped with a button. the animation object starts and stops, but not with a certain value (36 degrees). How to do?
Else. do you have tips on how to enter the number that comes out after a rotation stop in a text? I know how to do it, but the numbers are engraved on a texture, and I can’t figure out which way to go.
I need this example for the OGM game level which is part of an enigma …
I have Attached a package containing everything you’ve need (including the script) that I use for this test
Thank you all for any information and suggestions!
It’s going to be very tough to get an animation to stop at a specific degree point (unless the animation clip itself stops at that point), but you really don’t need to use an animation at all for this. All you’re doing is rotating in a single axis, which is dead simple to rotate in code, and you can much more easily round to the nearest number that way.
(Also you’ll find most people aren’t going to bother importing a unitypackage to answer forum questions, better to post script text in code tags with screenshots for any non-code stuff.)
So basically, you have a number representing your rotation, and you’ll probably want to set the rotation in LateUpdate based on this number. (Note: do not attempt to read the current rotation back out as Euler angles, that way lies madness. This is why we’re not going to use the physics engine for this.) If this is a slot machine, it probably also has speed and some deceleration rate.
public float rotValue = 0f;
public float rotSpeed = 0f; //degrees per second
public float rotFriction = 1f; //we'll subtract this per second
public float roundToDegrees = 36f;
void LateUpdate() {
transform.rotation = Quaternion.AngleAxis(rotValue, Vector3.right);
}
void Update() {
rotValue += rotSpeed * Time.deltaTime;
rotSpeed -= rotFriction * Time.deltaTime;
rotSpeed = Mathf.Max(rotSpeed, 0f); //stop at 0
And now, when the speed reaches 0, we want it to find the nearest rounded value and then move to it: