Question by
KiroHaregame · Feb 23, 2018 at 09:24 PM ·
rotationtext
How do I get a point every 360 degrees? (Unity 2017.2)
So I'm currently working on a game where you're getting points by spinning an object. But how can I give points every time it spins 360 degrees? I have this code. I couldn't figure out how to code that so I took one from the Forums.
public class ObjectRotation : MonoBehaviour
{
public float f_lastX = 0.0f;
public float f_difX = 0.5f;
public float f_steps = 0.0f;
public int i_direction = 1;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
f_difX = 0.0f;
}
else if (Input.GetMouseButton(0))
{
f_difX = Mathf.Abs(f_lastX - Input.GetAxis("Mouse X"));
if (f_lastX < Input.GetAxis("Mouse X"))
{
i_direction = -1;
transform.Rotate(Vector3.up, -f_difX);
}
if (f_lastX > Input.GetAxis("Mouse X"))
{
i_direction = 1;
transform.Rotate(Vector3.up, f_difX);
}
f_lastX = -Input.GetAxis("Mouse X");
}
else
{
if (f_difX > 0.5f) f_difX -= 0.05f;
if (f_difX < 0.5f) f_difX += 0.05f;
transform.Rotate(Vector3.up, f_difX * i_direction);
}
}
}
By testing this script I've seen that it's going to 180 degrees and then going to -180 degrees.
Comment
Your answer
Follow this Question
Related Questions
Space/Aircraft rotation 0 Answers
Camera Controller script as a child object,Camera Control as a Child Object for my Player 0 Answers
Object Rotation With Touch 0 Answers
Gyro Rotation Offest Calculation or Alternate Solution? 1 Answer
Not a programmer, but working on a game where I need to roll dice. 1 Answer