- Home /
Question by
mksguide · Feb 10, 2021 at 01:35 PM ·
c#androidscripting problemmethod
Script Runs Fine in Editor But Not on Android
The player health script which handles the player health is not working on Android. It works completely fine in Unity Editor.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerHealth : MonoBehaviour
{
public static float playerHealth;
public Image healthImage;
bool isEnemyAttacking = false;
public void DamageApply()
{
if (!isEnemyAttacking)
{
if (playerHealth > 0)
{
playerHealth -= 15f;
healthImage.fillAmount = playerHealth / 100f;
}
else
{
playerHealth = 0;
healthImage.fillAmount = 0f;
// PlayerDied();
}
isEnemyAttacking = true;
StartCoroutine(CoolDownTime());
}
}
/*
public void PlayerDied()
{
GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject enemy in enemies)
{
enemy.GetComponent<Enemy>().isPlayerDead = true;
}
}*/
IEnumerator CoolDownTime()
{
yield return new WaitForSeconds(1.2f);
isEnemyAttacking = false;
}
When the enemy hits the player, the script component then the enemy gets and calls the method ApplyDamage. I can see the health reducing in Unity Editor, and the health fill amount image is also decreasing, but on Android, nothing is happening. The playerHealth value is gets filled at the start of the game from the load method.
I also tried adding a text to see the health status on Android, but that did not change at all.
Comment