using System.Collections; using System.Collections.Generic; using UnityEngine; public class ParentBehaviour : MonoBehaviour { public spawner babySpawner; public GameObject child; public Texture baseVis; public Texture hatVis; public Texture eyeVis; public Texture topVis; public Texture bottomVis; public List order = new List(); public ParentBehaviour otherParent; public Texture2D[] parentBases; public Texture2D parentFaceNeutral; public Texture2D parentFaceHappy1; public Texture2D parentFaceHappy2; public Texture2D parentFaceAngry; public Texture2D parentFaceTalk; public GameObject parentBodyObj; public GameObject parentFaceObj; public GameObject parentDialougeObj; private void Start() { parentBodyObj.GetComponent().material.mainTexture = parentBases[Random.Range(0, parentBases.Length)]; parentFaceObj.GetComponent().material.mainTexture = parentFaceNeutral; } [ContextMenu("Get Random Child")] public void GetRandomChild() { bool _validChild = false; while (!_validChild) { int _childIndex = Random.Range(0, babySpawner.transform.childCount); child = babySpawner.transform.GetChild(_childIndex).gameObject; if (otherParent.child != null) { if (child != otherParent.child) { //this prevents both parents asking for the same child _validChild = true; } } } Randomizer _childRandomizer = child.GetComponent(); baseVis = _childRandomizer.baseObj.GetComponent().material.mainTexture; hatVis = _childRandomizer.hatObj.GetComponent().material.mainTexture; eyeVis = _childRandomizer.eyeObj.GetComponent().material.mainTexture; topVis = _childRandomizer.topObj.GetComponent().material.mainTexture; bottomVis = _childRandomizer.bottomObj.GetComponent().material.mainTexture; order.Insert(Random.Range(0, order.Count), "base"); order.Insert(Random.Range(0, order.Count), "hat"); order.Insert(Random.Range(0, order.Count), "eye"); order.Insert(Random.Range(0, order.Count), "top"); order.Insert(Random.Range(0, order.Count), "bottom"); } public bool CheckChild(GameObject _child) { if (_child == child) { return true; } else { return false; } } public Texture GiveDetails(GameObject _child) { for (int i = 0; i < order.Count; i++) { switch (order[i]){ case "base": if (child.GetComponent().baseObj.GetComponent().material.mainTexture != baseVis) { return baseVis; } break; case "hat": if (child.GetComponent().hatObj.GetComponent().material.mainTexture != hatVis) { return hatVis; } break; case "eye": if (child.GetComponent().eyeObj.GetComponent().material.mainTexture != eyeVis) { return eyeVis; } break; case "top": if (child.GetComponent().topObj.GetComponent().material.mainTexture != topVis) { return topVis; } break; case "bottom": if (child.GetComponent().bottomObj.GetComponent().material.mainTexture != bottomVis) { return bottomVis; } break; default: break; } } return null; } private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "child") { if (CheckChild(other.gameObject)) { //this is the correct child } else { Texture _displayGraphic = GiveDetails(other.gameObject); //display the display graphic parentDialougeObj.GetComponent().material.mainTexture = _displayGraphic; } } } }