Search Unity

Rotate wheels of a slot machine

Discussion in 'Scripting' started by unileven95, May 19, 2019.

  1. unileven95

    unileven95

    Joined:
    May 19, 2019
    Posts:
    1
    Hey

    I'm trying to do a slot machine which has 3 wheels. I've used 3 resized cylinders to make the wheels and I've put the right texture on it :



    Now I'm trying to make this damn wheel rotate (similarly to car wheels) smoothly . As there are 16 pictures printed around it, I'd like to make it rotate by an angle of N*22,5°, N being a random integer

    I've tried bunch of things, unsuccessfully... The last thing I've tried is this :

    Code (CSharp):
    1. if (Input.GetKey (KeyCode.UpArrow)) {
    2.       Vector3 direction = new Vector3 (this.transform.eulerAngles.x + (22.5 * N), 0, 90);
    3.       Quaternion targetRotation = Quaternion.Euler (direction);
    4.       this.transform.rotation = Quaternion.Lerp (this.transform.rotation, targetRotation, Time.deltaTime * 2);
    5. }
    But it doesn't work.. Does anyone know how should I proceed ?