- Home /
C# Instantiate not working after build "Android"
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);
}
Hello,
What this line instantiate?
Instantiate(hitFX,transform.position,Quaternion.identity);
why hitFX instantiated twice??
what this line instantiate?
Instantiate(dead,transform.position,Quaternion.identity);
what collider you used.2d or 3d box or spear does it contain rigidbody ??
Instantiate(Coin,transform.position,transform.rotation);
what is the transform position.
Answer by Flarvain · Sep 25, 2018 at 03:31 AM
This is an old one but i'm getting the same issue at the moment, has anyone got a solution for this?
I have a public prefab and it spawns perfectly in the editor (i have 0 errors in my code that are displaying) yet simple doesn't spawn for android.
Answer by SamohtVII · Sep 25, 2018 at 04:44 AM
Try in the "Quality Settings" tab. The player runs with High settings and Android will run with low settings. Make sure you are running low settings in the editor also to match what you see on Android. Not sure if this will help but worth a shot.
Your answer
![](https://koobas.hobune.stream/wayback/20220613143058im_/https://answers.unity.com/themes/thub/images/avi.jpg)