Hi everyone I’m making a small 2D game for mobile devices and i’m encountering a problem
I did search the forums for a solution to this I found out that others had the similar problem but I didn’t find a solution.
What I want to do is when I kill a enemy, the enemy will drop (1) Coin. The code that i’m using works great on unity editor, but after I build it for Android, the enemies just wont die and drop the coin.
The problem is that with InstantiateCoin(); - Enemies won’t even die.
Without the code InstantiateCoin(); - Enemies die but of course Coin wont drop that way.
Any suggestions for another solution would be appreciated!
Thanks.
— the code —
public void Hit(int _damage)
{
//Instantiate hit FX
Instantiate(hitFX,transform.position,Quaternion.identity);
//Remove the damage value from the health
hp -= _damage;
//If health is less than 0
if (hp <= 0)
{
//Instantiate hit FX
Instantiate(hitFX,transform.position,Quaternion.identity);
//Instantiate dead FX
Instantiate(dead,transform.position,Quaternion.identity);
//Spawn Coin
InstantiateCoin();
//Destroy
Destroy(gameObject);
}
}
void InstantiateCoin()
{
//Spawn enemy
Instantiate(Coin,transform.position,transform.rotation);
}