Error:Invalid parameter pos in Collider.FetchPoseFromTransform because it was infinity or NaN
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cubejump : MonoBehaviour
{
public GameObject maincube;
private bool animate, jumped;
private float scratch_speed = 0.5f, startTime;
void FixedUpdate()
{
if (animate && maincube.transform.localScale.y > 0.4f)
PressCube(-scratch_speed);
else if (!animate) {
if (maincube.transform.localScale.y < 1f)
PressCube(scratch_speed * 3f);
else if (maincube.transform.localScale.y != 1.5f)
maincube.transform.localScale = new Vector3(1f, 1f, 1f);
}
if(maincube.GetComponent <Rigidbody> ())
{
if (maincube.GetComponent<Rigidbody>().IsSleeping() && jumped)
{
print("Next One");
maincube.transform.eulerAngles = new Vector3(0f, maincube.transform.eulerAngles.y, 0f);
}
}
}
void OnMouseDown()
{
if (maincube.GetComponent<Rigidbody>())
{
animate = true;
startTime = Time.time;
}
}
void OnMouseUp()
{
if (maincube.GetComponent<Rigidbody>())
{
jumped = true;
animate = false;
float force, diff;
diff = Time.time - startTime;
if (diff < 3f)
force = 190 * diff;
else
force = 300f;
if (force < 60f)
force = 60f;
maincube.GetComponent<Rigidbody>().AddRelativeForce(maincube.transform.up * force);
maincube.GetComponent<Rigidbody>().AddRelativeForce((maincube.transform.forward * -1 + maincube.transform.up).normalized * force);
}
}
void PressCube(float force){
maincube.transform.localPosition += new Vector3(0f, force * Time.deltaTime, 0f);
maincube.transform.localScale += new Vector3(0f, force * Time.deltaTime, 0f);
}
}