Question by
Hexyes · Aug 18, 2017 at 08:11 PM ·
gameobjectexternalattribute
exterior GameObject reference.
so I've got projectiles, and they are properly detecting collisions. here's what i'm having trouble with: i want my projectile to force my player (or enemy) object to decrement it's health. so I tried using this (inside the projectile):
void OnCollisionEnter(Collision col){
GameObject actor = col.gameObject;
if(actor.name == "Player"){
actor.PlayerStats.takeDamage(1);
}
the issue is that i keep getting an error of GameObject has no definition of PlayerStats. so my question is how do i go about referencing a specific game object named player that has an attached script of PlayerStats?
Comment
Best Answer
Answer by Hexyes · Aug 19, 2017 at 12:55 AM
and now i got it figured out. so for anyone who stumbles upon this the solution was:
void OnCollisionEnter(Collision collision)
{
GameObject actor = collision.gameObject;
if (actor.name == "Player")
{
PlayerStats temp = collision.gameObject.GetComponent<PlayerStats>();
temp.takeDamage(1);
}else{
}
Destroy(gameObject);
}