- Home /
How can i count full rotations of object and then add point for each one
IEnumerator WaitForTouchRelease() { while(true) { if(Input.GetMouseButtonUp(0)) { pos1 = MakeFormula(Input.mousePosition.y / Screen.height);
dist = pos1 - pos0;
break;
}
yield return 0;
}
m_rig.AddForce(Vector2.up * dist * forceMult);
m_rig.AddTorque(rotateSpeed);
PlaySoundBounce();
yield return new WaitForSeconds(1);
floorTouched = false;
}
public Text textPoint;
int point = 0;
void Add1Point()
{
point++;
if(textPoint != null)
textPoint.text = point.ToString();
PlaySoundSuccess();
}
void OnCollisionEnter2D(Collision2D coll)
{
if(floorTouched)
return;
floorTouched = true;
PlaySoundCollision();
StartCoroutine(WaitForVelocityNull());
}
IEnumerator WaitForVelocityNull()
{
while(m_rig.velocity.y != 0)
{
yield return 0;
}
yield return new WaitForSeconds(0.5f);
if(m_rig.transform.eulerAngles.z < 15)
{
m_rig.velocity = Vector2.zero;
Add1Point();
StartCoroutine(WaitForFirstTouch());
}
else if(m_rig.transform.eulerAngles.z > 359)
{
m_rig.velocity = Vector2.zero;
Add1Point();
StartCoroutine(WaitForFirstTouch());
}
else
{
textPoint.text = "Game Over";
Util.SetLastScore(point);
ShowAds();
yield return new WaitForSeconds(0.2f);
Util.ReloadLevel();
}
}
Comment
You will need to store the rotation yourself. Unity's rotational unit, a Quaternion, is in fact a "Unit" Quaternion: it specifies an orientation, NOT an amount of rotation.
In other words, all the Euler angles are "clipped" to 360 degress (I think between -180 and +180, but could be 0 to 360, I always forget).
So, you will NEVER get a true result for this line: if(m_rig.transform.eulerAngles.z > 359)