This question was
closed Mar 31, 2016 at 06:12 AM by
carlqwe for the following reason:
Problem is not reproducible or outdated
Find Script and call function FROM hit.transform
hey, Got a major problem here. Trying to access a function in an other script but it needs to be recognised from a hit.transform. (So that object i hit with my raycast will call the funciton ONLY THAT SPECIFIC GAMEOBJECT)
But i get errors Please help (: ~carlqwe
script that i want to call from:
function Update ()
{
if (Physics.Raycast (ray, hit, 10))
{
if(hit.transform.gameObject.tag == "NPC")
{
Debug.Log("hit with tag 'npc'");
//GET ERROR RIGHT HERE
hit.transform.GetComponent(EnemyHealth).ApplyDammage();
}
}
}
//EnemyHealthScript
function ApplyDammage ()
{
Health -= TheDammage;
Debug.Log("TookDammage");
}
Comment
Follow this Question
Related Questions
How to find nearby objects? 2 Answers
how do I call a function from another script, when Raycast Hits? 1 Answer
Third person shooter need some help 0 Answers
Making a portal inspired game - Need help! 0 Answers
LineRenderer doesn't go to Hit.Point 1 Answer