Line 22 —> enemy.DamageEnemy(PlayerStats.instance.bulletDamage);
Any idea how I can convert it to a float? Thanks!
Script:
using UnityEngine;
using System.Collections;
public class DamageEnemyCollision : MonoBehaviour
{
private Enemy enemy = null;
void Start()
{
if (GameObject.FindGameObjectsWithTag("Enemy") != null)
{
GameObject go = GameObject.FindGameObjectsWithTag("Enemy")[0];
enemy = go.GetComponent<Enemy>();
}
}
void OnCollisionEnter2D(Collision2D coll)
{
if ((coll.gameObject.tag == "Enemy") && (enemy != null))
{
enemy.DamageEnemy(PlayerStats.instance.bulletDamage);
}
}
}
If you need it
Enemy Script:
using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
[System.Serializable]
public class EnemyStats {
public int maxHealth = 100;
public int scoreDrop = 10;
private int _curHealth;
public int curHealth
{
get { return _curHealth; }
set { _curHealth = Mathf.Clamp (value, 0, maxHealth); }
}
public void Init()
{
curHealth = maxHealth;
}
}
public EnemyStats stats = new EnemyStats();
[Header("Optional: ")]
[SerializeField]
private StatusIndicator statusIndicator;
void Start()
{
stats.Init ();
if (statusIndicator != null)
{
statusIndicator.SetHealth (stats.curHealth, stats.maxHealth);
}
}
public void DamageEnemy (int damage) {
stats.curHealth -= damage;
if (stats.curHealth <= 0)
{
GameMaster.KillEnemy (this);
}
if (statusIndicator != null)
{
statusIndicator.SetHealth (stats.curHealth, stats.maxHealth);
}
}
}