Hi all,
I am trying to set up a script that will enable a specific child of an object when a raycast hits it, and disable it when it doesn’t hit it. I’ve tried everything and haven’t found a solution for what I’m looking for. I found the ActiveRecursive method, but all I’ve been able to do with that is deactivate al the children and the parent, and then reactivate the parent. I’d also like to know how to access certain parts of the child, such as a particle emitter’s emit property. I’ve only been scripting for a few days, so bear with me. This is what I’ve got so far:
var rayHit : RaycastHit;
var delayTime : float = 0;
function FixedUpdate () {
var delayAmount : float = .2;
if (Time.time > delayTime) {
var fwd = transform.TransformDirection(Vector3.forward);
Screen.lockCursor = true;
Debug.DrawRay (transform.position, transform.TransformDirection(Vector3.forward) * 5, Color.white);
if (Physics.Raycast(transform.position, fwd, rayHit, 5)) {
//if () {
rayHit.collider.gameOnject.GetChild("Sphere").active = false;
//}
//Debug.Log(rayHit.name);
//Debug.Log(rayHit.gameOnject.GetChild("Sphere").name);
}
delayTime = Time.time + delayAmount;
//Debug.Log(Time.time + " " + delayTime);
}
}
So I’ve got a variable (delayTime and delayAmount) that will make the function update every 0.2 seconds, I’ve got a ray cast shooting a ray 5 units ahead of me, and i’d like to have an if statement along the lines of:
if the ray hits and object that has a child named “outline”, then activate the object (or it’s mesh render)
else, then deactivate the object.
Any help would be greatly appreciated, thanks in advance!