- Home /
Cannot get script component while the game object has a refered script
i have a problem with GetComponent
the camera is child object of character object and the camera has a script "mouseHit", it has setCanAttack() method.
When character collide with a waypoint trigget, the trigger must get script mouseHit from camera object to use setCanAttack() method but the thing happened that it get null object
i tried GetComponentInChildren(mouseHit) but no effective i declared variable to keep camera gameObject, drag-drop into the trigger and try to access the script but no effective either.
how can i fix this?
ps. i write it in javaScript.
Answer by DaveA · Jul 21, 2011 at 03:40 PM
Try var mh : mouseHit = Camera.main.GetComponentInChildren("mouseHit")
BTW It is commonpractice to Captialize functions and classes (script names) and lower case the first letter of variables, to help keep them cognitively distinct.
Your answer
Follow this Question
Related Questions
Super mario Camera Script 0 Answers
I Made a Revolver Script, But It's Saying There is an Error 2 Answers
access a script generically? 2 Answers
Code works in editor, but not in built game. 1 Answer
Changing Camera Culling Mask in Script *Javascript* 0 Answers