Hi,I setted the bullet script that when i shot a player his healthbar take 10% damage,but when i shoot a player his healthbar go to 10%.
Bullet Script:
void OnCollisionEnter(Collision collision)
{
GameObject hit=collision.gameObject;
Health health=hit.GetComponent<Health>();
if (health != null)
{
health.TakeDamage(10);
}
Destroy(gameObject);
}
Health Script:
public const int maxHealth = 100;
public int currentHealth = maxHealth;
public RectTransform healthbar;
public void TakeDamage(int amount)
{
currentHealth = amount;
if (currentHealth <= 0)
{
currentHealth = 0;
Debug.Log("Dead");
}
healthbar.sizeDelta = new Vector2(currentHealth * 2, healthbar.sizeDelta.y);
}
}
Sorry for my bad English,
Wrasty