- Home /
Raycast Help
I made this script but I am having promblems with it. I want it to change a boolean on another object so you can interact with it. I am trying to use GetComponent as well. thank you for your help. And I hope you have a great day.
pragma strict
ar Range : int = 1;
function Update () {
if (Input.GetButtonDown ("Interact")) {
var hit : RaycastHit;
var fwd = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast (transform.position, fwd, Range)&& tag == ("Interact"))
{
var InteractedObject = hit.GetComponent(MyInteraction);
}
}
}
Answer by Em3rgency · Jul 04, 2013 at 06:58 PM
I'm no js expert, but I believe it should go something like
var InteractedObject : MyInteraction = hit.transform.GetComponent(MyInteraction);
InteractedObject.yourBoolean = false;
Thank you I thought of doing that but I always doubted myself so thank you. but there is a error message it is telling me that GetComponent is not a member of RaycastHit.
$$anonymous$$y bad, it should be hit.transform.getcomponent. Edited answer.
Thank you so much for helping me out because as you can tell I am not the best programmer. so thanks again.
wait srry for asking another question but I just tested it and it didnt work this is what I we have so far (and I said we because you helped me)
pragma strict
ar Range : int = 1;
function Update () {
if (Input.GetButtonDown ("Interact")) {
var hit : RaycastHit;
var fwd = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast (transform.position, fwd, Range)&& tag == ("Interact"))
{
var InteractedObject : $$anonymous$$yInteraction = hit.transform.GetComponent($$anonymous$$yInteraction);
InteractedObject.IsActive = true;
}
} }
Your answer
Follow this Question
Related Questions
C# Check Physics.Raycast Once 0 Answers
A node in a childnode? 1 Answer
Enemy damage error 1 Answer
Stop animation when no more bullets 1 Answer
C# More Accurate or Larger Raycast 1 Answer