- Home /
Question by
dpcamp · Jan 31, 2014 at 02:45 AM ·
gameobjectpowerup
Changing a Player's GameObject when damaged/powerup
Hi, I'm about 2 weeks into learning Unity and C# so bare with me.
I'm making a Mario clone so i can understand how this all works, and have been relying heavily on the 2D tutorial and some other resources on how this all works.
I've set up 2 separate game objects for mario, one big one small, in my code i'm using health to determine what version of mario appears.
public GameObject marioHealth1;
public GameObject marioHealth2;
void Start ()
{
anim = GetComponent<Animator> ();
marioControl = GetComponent<MarioControls> ();
}
// Update is called once per frame
void FixedUpdate ()
{
anim.SetBool ("Dead", isDead);
if (health <= 0 && !isDead)
{
Death ();
}
if (health == 1)
{
Instantiate (marioHealth1, gameObject.transform.position, gameObject.transform.rotation);
Destroy (gameObject);
}
}
This works but i'm sure this isn't the way to do this, i noticed that the camera stops following the player which i'm assuming that's because i destroyed the game object and i'm positive theres going to be other issues as i get further into this.
what would be the best method to achieve this?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613132137im_/https://answers.unity.com/themes/thub/images/avi.jpg)