I am new to Unity and c# and want to make a freeze effect for a projectile so you can freeze the object, where they would stop moving, and then unfreeze them. Freezing them is easy, as i can just make them kinematic, or just make their velocity 0(Which is what i did, as i turned off gravity) but making then unfreeze is a nightmare. I am trying to store their velocity in a seperate Vector3 array but it just wont work. Help!
public class BulletPause : MonoBehaviour
{
Rigidbody rb;
Vector3[] PreviousSpeed;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if(GameObject.Find("FirstPersonPlayer").GetComponent<PauseBehaviour>().IsPaused == true)
{
int[] PreviousSpeed = new Vector3[rb.velocity.GetLength(0)];
rb.velocity.CopyTo(PreviousSpeed, 0);
rb.velocity = new Vector3(0, 0, 0);
}
if (GameObject.Find("FirstPersonPlayer").GetComponent<PauseBehaviour>().IsPaused != true)
{
rb.velocity = PreviousSpeed();
}
}
}
,I am very new to Unity and want to make a simple freeze mechanic for this object, so i can stop them freeze them, and then unfreeze with the same velocity i froze them with. Freezing them is easy, but un freezing is I found challenging, i tried storing their velocity before the freeze in a vector3 array but it wont copy over. Help!
public class BulletPause : MonoBehaviour
{
Rigidbody rb;
Vector3[] PreviousSpeed;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if(GameObject.Find("FirstPersonPlayer").GetComponent<PauseBehaviour>().IsPaused == true)
{
int[] PreviousSpeed = new Vector3[rb.velocity.GetLength(0)];
rb.velocity.CopyTo(PreviousSpeed, 0);
rb.velocity = new Vector3(0, 0, 0);
}
if (GameObject.Find("FirstPersonPlayer").GetComponent<PauseBehaviour>().IsPaused != true)
{
rb.velocity = PreviousSpeed();
}
}
}