- Home /
GetComponent
I need some help with this GetCompnent peice of code:
 if(hit.GameObject.tag == "Head")
     Enemy.GetComponent(dead) = true;
I am afraid that I don't know anything about GetCompnent, and after a long time trying to figure this puzzle out, I have not gotten anywhere.
EDIT
This is my own script. It uses raycast as bullets, and hit is the variable used in the raycast function.
You can't just "Set" a "Get" method. As in, the value you asked from GetComponent is just a copy from the original value. So changing that value, won't affect the original one.
- 49 _ GameObject.Find and GetComponent : http://youtu.be/WPpkGGEtz7$$anonymous$$ 
- 50 _ GameObject.Find and GetComponent : http://youtu.be/Yh3bkHf$$anonymous$$NEk 
- 51 _ Understanding GameObject.Find : http://youtu.be/eQlFxm-o2L4 
- 52 _ Understanding GameObject.Find : http://youtu.be/TBu9RaU5jjs 
- 53 _ Understanding GetComponent : http://youtu.be/n-$$anonymous$$vNT4yQx$$anonymous$$ 
I have heard somewhere that this is a well-documented function, perhaps maybe even Unity posted something about it? $$anonymous$$aybe google it?
Answer by robertbu · Mar 30, 2013 at 11:29 PM
GetComponent() gets access to a script instance attached to a game object. So in theory, you are getting access to the 'dead' script. But there are a couple of things that don't make sense to me with this code. Usually you would see something like:
 enemy.GetComponent(Enemy).dead = true;
Plus it is difficult to see how the head hit maps to a specific enemy. Is this a script you got somewhere? Can you post the rest of the code?
Your answer
 
 
             Follow this Question
Related Questions
GetComponent in the Update function? 1 Answer
Get component in parent 2 Answers
2D Animation does not start 1 Answer
Why wont this work? (I've done similar 1000 times fine) 1 Answer
boolean questions get, set, in java. 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                