First of all I am new to unity as will as C#, I want to create a wheelof fortune for my game using C# where you could rotate it with mouse.I wrote this code in C# it works good but the only problem is I don’t know how to add friction 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).
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);
}
}
}
any help will be much appreciated?