- Home /
Making child components interactive c#?
I followed a tutorial on youtube that showed how to make one interactive object, but I want to put this script on a parent object and have it effect all the child components as well. I basically have a model of a church and it has over 300 parts to it (all meshes). The script I used to make one gameObject interactive looks like this:
using UnityEngine;
using System.Collections;
public class InteractHighlight : MonoBehaviour {
public GUIText target;
private bool selected = false;
private PopupWindow myPopupWindow;
// Use this for initialization
void Start () {
myPopupWindow = GetComponent<PopupWindow> ();
}
// Update is called once per frame
void Update () {
selected = false;
}
public void OnLookEnter (){
renderer.material.color = Color.red;
target.text = "Left Click for More Info";
selected = true;
}
void OnGUI (){
if(Input.GetMouseButtonDown(0) && selected) {
myPopupWindow.enabled = true;
}
}
}
The script works if I manually attach it one mesh at a time (plus the other indicated stuff, GUItext, popup script etc), but there's no way I could possibly do that in a reasonable amount of time. Is there a way to make this script apply to the child components as well or would it be better to try and integrate the interactivity script with my raycast script (which is attached to the fps controller)?
Also is there a quick way of attaching mesh colliders to each part of the church?
Thanks in advance
If you highlight all the objects in the hierarchy, you can add components to all of them and configure them simultaneously.