- Home /
Changing bool of raycasthit.parent
Hello there!
I'm looking to change the bool of a raycasthit's parent.
Current Script:
static var dTog : boolean;
var hit : RaycastHit;
function Update()
{
Debug.DrawRay (transform.position, transform.forward, Color.red);
if(Physics.Raycast(transform.position, transform.forward, hit, 100.0))
{
if(hit.collider.CompareTag("button"))
{
if(Input.GetKeyDown(KeyCode.E))
{
hit.transform.parent.thisD = !hit.transform.parent.thisD;
print("door is open/close");
}
}
}
}
Currently this gives me nothing but a "Enumerable 1 Error".
Is there anything you guys can see wrong in it? :)
I would appretiate the help greatly! Sincerely,
Bakos133
Thank you! Your solution opened my eyes. I have been stuck on this issue for quite some time now. Now onto ghost objects ^_^ haha
If you're using UnityScript you should put the compiler directive #pragma strict at the top of your script. In this case it would have given you a compiler error and told you how to fix it.
Compilers are smart. Use them to their full potential ;)
Answer by KellyThomas · Dec 28, 2013 at 04:38 AM
hit.transform.parent is of type Tranform.
You will need to call GetComponent() if you want to access an attached script.
Your answer
Follow this Question
Related Questions
Raycast returns null for no apparent reason 0 Answers
Need Help with RayCast. No Vector? 1 Answer
Raycast goes through 1 Answer