I have a game object, and it has two children objects inside it. When the player collides with a trigger on the parent object I want the two children objects to move in a certain way. The script is attached to the parent. I was thinking it could find the children by name. Lets call them Child_1 and Child_2 and the parent object will be called ParentObj
Im just not sure how to go about finding the children.
I have laid out the basics. I just need a way to find the actual child and plug it into my little place holders.
using UnityEngine;
using System.Collections;
public class StandardDoor : MonoBehaviour {
private Vector3 pos;
public Vector3 target;
void Start() {
pos1 = Child_2 GOES HERE .transform.position;
pos1.y += 0;
target1 = Child_2 GOES HERE .transform.position;
target1.y += 3;
pos2 = Child_2 GOES HERE .transform.position;
pos2.y += 0;
target2 = Child_2 GOES HERE .transform.position;
target2.y -= 3;
}
void OnTriggerEnter (Collider other) {
if (other.tag == "Player") {
Debug.Log("collide");
Child_1 GOES HERE .transform.position = Vector3.MoveTowards(target, pos, 0.1f);
Child_2 GOES HERE .transform.position = Vector3.MoveTowards(target, pos, 0.1f);
}
}
void OnTriggerExit (Collider other) {
if (other.tag == "Player") {
Debug.Log("not collide");
Child_1 GOES HERE .transform.position = Vector3.MoveTowards(pos, target, 0.1f)
Child_2 GOES HERE .transform.position = Vector3.MoveTowards(pos, target, 0.1f)
}
}
}
thanks in advance.