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();
}
}