storing velocity and temporarly using it
this script is meant to turn on four objects when the asteroid is destroyed. those four objects are it's fragments, so i would like for them to have the same velocity as the destroyed asteroid. the only problem is that after the fragment's velocity is set as the asteroid's velocity (currentvelocity) it cannot be changed. i want a sort of a timer that would turn off the frag = currentvelocity part of the script, or maybe some way of setting the velocity only once after the asteroid is destroyed. is there any way to acomplish that?
void Update()
{
if(asteroid == true){
self.transform.position = new Vector3(asteroid.transform.position.x, asteroid.transform.position.y, asteroid.transform.position.z);
Vector3 eulerRotation = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, asteroid.transform.eulerAngles.z);
self.transform.rotation = Quaternion.Euler(eulerRotation);
CurrentVelocity = asteroid.GetComponent<Rigidbody2D>().velocity;
}
else{
frag1.SetActive(true);
frag2.SetActive(true);
frag3.SetActive(true);
frag4.SetActive(true);
frag2.GetComponent<Rigidbody2D>().velocity = CurrentVelocity;
frag3.GetComponent<Rigidbody2D>().velocity = CurrentVelocity;
frag4.GetComponent<Rigidbody2D>().velocity = CurrentVelocity;
frag1.GetComponent<Rigidbody2D>().velocity = CurrentVelocity;
}
}
Your answer
Follow this Question
Related Questions
I want to rotate the 2D missile with touch controls 1 Answer
How to get scripts to detect foreign variable change? 0 Answers
How to make a floppy object 1 Answer
Add Force isnt working 1 Answer
destory object not variable 2 Answers