so i have this basic enemy script that works fine
public class Enemy : MonoBehaviour
{
public float health;
public float damage;
public GameObject deatheffect;
public void Update()
{
if (health <= 0)
{
Instantiate(deatheffect,transform.position,transform.rotation);
Destroy(gameObject);
}
}
void OnTriggerEnter(Collider hitInfo)
{
Player player = hitInfo.GetComponent();
if (player != null)
{
player.health -= damage;
health -= player.attackPower;
}
}
}
but i have a boss that instantiates an object for a health debuff and i dont want the debuff to use collision. i just want the player to lose health on the debuffs Start.
so how do i change the OnTriggerEnter to Start.ive tried this
public class testfox : MonoBehaviour
{
public float attackBuff;
public float damage = 4;
public GameObject player;
void Start()
{
player = GameObject.Find("Player");
player.health -= damage;
Destroy(gameObject);
}
},i have this basic enemy code that works for collision but i want to make a version for a boss that damages the player on start but i cant figure out how to access the player without colliders
public class Enemy : MonoBehaviour
{
public float health;
public float damage;
public GameObject deatheffect;
public void Update()
{
if (health <= 0)
{
Instantiate(deatheffect,transform.position,transform.rotation);
Destroy(gameObject);
}
}
void OnTriggerEnter(Collider hitInfo)
{
Player player = hitInfo.GetComponent();
if (player != null)
{
player.health -= damage;
health -= player.attackPower;
}
}
}
↧