Hi, I’m making simple shoot’em up game for Android and I’ve occured a weird problem. I want my enemies to shoot per 3 seconds. I’ve created Shoot() function in class that enemy class inherits from:
public void Shoot()
{
if (canShoot)
{
GameObject Bullet = Instantiate(BulletPref);
Bullet.transform.position = transform.position;
var script = Bullet.GetComponent<BulletMovement>();
script.damage = weaponDamage;
script.direction = fireDirection;
Bullet.gameObject.tag = tag;
canShoot = false;
StartCoroutine(Reload());
}
}
IEnumerator Reload()
{
yield return new WaitForSeconds(fireRatio);
canShoot = true;
}
That function is also used by a player object. When I build the game and run it on my phone, player’s Shoot() function works very well. However, enemies seem to fire all the time. I’m 99% sure that their fireRatio is set to 3.0f. What can cause it and how to fix that?
EDIT: What is more, when I use game preview in Unity on PC everything works perfectly…
If you’re running in debug mode (with the phone plugged into your PC and everything, so you can see console messages while running the game), try adding a Debug.Log message inside your Reload function or something to make sure fireRatio is 3 and not something else.
If you don’t have console access, throw a quick script together that updates a UI text with the value every frame. If it’s working on your PC preview and not on your device, that’s the only way I’d be sure of what’s really going on in that other environment.
1 Like
Didn’t know about Debug.Log, that’s my first time doing a mobile game. I’ll check that immidiately 
Debug.Log logs to your console. I use it constantly as I develop.
The thing with developing for mobile is that you don’t have access to the console unless the phone is running in debug mode, connected to the computer, and linked with your devkit in some way. I haven’t tinkered with Android much, so I’m guessing that’s Android Studio or something. With iOS, my Debug.Log messages get sent to XCode.
Sooo… I checked fireRatio and as I supposed, it is set to 3.0f correctly. That’s not it. It seems like coroutine for enemy doesn’t work, but I have no idea why. At least I have debugger now 
Alright, found it. Enemy prefab has tag set to “Enemy”, but Android seems to ignore that. If I set tag in Start() works properly.