- Home /
Child instantiated object to RayCastHit's parent.
Hello everyone! As the title suggests, I am trying to child an instantiated object to the PARENT of another object via RayCastHit.
The current code I am using childs a new instantiated object to hit.transform. What I need is it to child it to hit.transform's parent. I have tried hit.transform.parent, but no luck.
I have also looked up my issue through-out google and I have come here as the last resort.
If anyone in the community has the solution to my problem, please help as the answer has eluded me for FARRR too long :(
function Build()
{
if (HitBlock() && hit.transform.tag == "Block")
{
if(sel1 == true)
{
var interF = GameObject.Instantiate(interFloor);
interF.transform.position = hit.transform.position + hit.normal;
interF.transform.tag = "Block";
interF.transform.parent = hit.transform;
}
}
}
Answer by robertbu · Dec 18, 2013 at 06:26 AM
I'm not sure I get you, but I think you want:
interF.transform.parent = hit.transform.parent;
This will make 'interF' a child of the parent of the object hit by the raycast.
Only thing is, I have tried that and I am having no luck. No errors, no parenting, just objects spawning on their own :(
-.- ... wow... are you kidding me. Lmao the moment you say it, it decides to work -.- GAHHHH hahahah Thank you sir, favourite answer right here.
Your answer
Follow this Question
Related Questions
Finding a RaycastHit tag (Null Reference Exception) 2 Answers
Move hit.point 1 Answer
Push object in direction of camera 0 Answers