Fortune Wheel in C#

Hi there,

First of all I am new to unity I just jumped off Game Maker and start learning unity3D and I followed some of tutorial in Learn I find it very different than game maker but I was also pretty impressed how easy and fun it is to learn :wink:

Now I want to create a fortune wheel for my game using C# so, does anyone know how create a fortune wheel where you could drag/rotate it with mouse.

Any help will be much appreciated,

any help plz?

You could probably start by looking up rotate in the Unity Script Reference. Then check Input and the mouse functions.

Ok, I write this code in C# it works good but the only problem is I don’t know how to add acceleration to it so that if I release the mouse button it should still continue rotating and slow down until it fully stopped (Just like a realistic Fortune Wheel).
any help plz?

using UnityEngine;
using System.Collections;

public class RotateCSharp : MonoBehaviour
{
    public int speed;
    public float lerpSpeed;
    float xDeg;
    float yDeg;
    Quaternion fromRotation;
    Quaternion toRotation;


    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            xDeg -= Input.GetAxis("Mouse X") * speed;
            fromRotation = transform.rotation;
            toRotation = Quaternion.Euler (yDeg,xDeg,0);
            transform.rotation = Quaternion.Lerp(fromRotation, toRotation, Time.deltaTime * lerpSpeed);
        }
    }
}

That’s because all your code is inside the if clause. You can put an ā€œelseā€ clause with the same code. So you might use something like a startSpeed and then in the input clause: xDeg = startSpeed. It wouldn’t start slowing down until you released the mouse button, I don’t think, it would just turn at the same speed while holding it down.

sorry didn’t catch it well :face_with_spiral_eyes: as I said I am new to Unity as will as C#, it will be easier for me if you could explain it or even us it in script so that i could understand it.

if(input blah blah){
xDeg = startSpeed;
//rest of code to slow down wheel and rotate;
}
else{
//rest of code to slow down wheel and rotate;
}

Ok so, I edited my code now its kind of worked but not the way I wanted because there is still two problems:

  1. Why it slow down in opposite direction?
  2. It just slowing down in a normal speed [-1] deduction which is not realistic how to fix this?
using UnityEngine;
using System.Collections;

public class RotateCSharp : MonoBehaviour
{
    public int speed;
    public float lerpSpeed;
    public float autoAcceletor;

    float xDeg;
    float yDeg;

    Quaternion fromRotation;
    Quaternion toRotation;


    void Update()
    {
        AutoAcceletor();

            if (!Input.GetMouseButton(0))
                    {
                        xDeg = autoAcceletor;
                    }
            else
                    {
                        xDeg -= Input.GetAxis("Mouse X") * speed;
                        autoAcceletor = xDeg;
                    }

        fromRotation = transform.rotation;
        toRotation = Quaternion.Euler (yDeg,xDeg,0);
        transform.rotation = Quaternion.Lerp(fromRotation, toRotation, Time.deltaTime * lerpSpeed);

    }

    void AutoAcceletor()
    {
        if (xDeg>0)
        {
            autoAcceletor --;

        }
        else if (xDeg<0)
        {
            autoAcceletor ++;
        }
    }
}

any help plz?