- Home /
accesing scripts throu raycasthit
RaycastHit hit;
if(Physics.Raycast(transform.position,transform.forward,out hit,targetDistance)){
}
as you can see its very basic what im tring to do is get into the scripts I have tried going throu with transform.parent with no avail and few others stepped away for a bit came back and still no ideas any help would be great.
Comment
Best Answer
Answer by robertbu · May 31, 2013 at 02:34 AM
Assuming you had a possible script named "TheScript" attached to another game object, you could do:
RaycastHit hit;
if(Physics.Raycast(transform.position,transform.forward,out hit,targetDistance)){
TheScript ts = hit.collider.gameObject.GetComponent< TheScript >();
if (ts != null)
ts.ExetueSomething();
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613103238im_/https://answers.unity.com/themes/thub/images/avi.jpg)