Global Game Jam 2021
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ParentBehaviour : MonoBehaviour
  5. {
  6. public spawner babySpawner;
  7. public GameObject child;
  8. public Texture baseVis;
  9. public Texture hatVis;
  10. public Texture eyeVis;
  11. public Texture topVis;
  12. public Texture bottomVis;
  13. public List<string> order = new List<string>();
  14. public ParentBehaviour otherParent;
  15. public Texture2D[] parentBases;
  16. public Texture2D parentFaceNeutral;
  17. public Texture2D parentFaceHappy1;
  18. public Texture2D parentFaceHappy2;
  19. public Texture2D parentFaceAngry;
  20. public Texture2D parentFaceTalk;
  21. public GameObject parentBodyObj;
  22. public GameObject parentFaceObj;
  23. public GameObject parentDialougeObj;
  24. private void Start()
  25. {
  26. parentBodyObj.GetComponent<MeshRenderer>().material.mainTexture = parentBases[Random.Range(0, parentBases.Length)];
  27. parentFaceObj.GetComponent<MeshRenderer>().material.mainTexture = parentFaceNeutral;
  28. }
  29. [ContextMenu("Get Random Child")]
  30. public void GetRandomChild()
  31. {
  32. bool _validChild = false;
  33. while (!_validChild)
  34. {
  35. int _childIndex = Random.Range(0, babySpawner.transform.childCount);
  36. child = babySpawner.transform.GetChild(_childIndex).gameObject;
  37. if (otherParent.child != null)
  38. {
  39. if (child != otherParent.child)
  40. {
  41. //this prevents both parents asking for the same child
  42. _validChild = true;
  43. }
  44. }
  45. }
  46. Randomizer _childRandomizer = child.GetComponent<Randomizer>();
  47. baseVis = _childRandomizer.baseObj.GetComponent<MeshRenderer>().material.mainTexture;
  48. hatVis = _childRandomizer.hatObj.GetComponent<MeshRenderer>().material.mainTexture;
  49. eyeVis = _childRandomizer.eyeObj.GetComponent<MeshRenderer>().material.mainTexture;
  50. topVis = _childRandomizer.topObj.GetComponent<MeshRenderer>().material.mainTexture;
  51. bottomVis = _childRandomizer.bottomObj.GetComponent<MeshRenderer>().material.mainTexture;
  52. order.Insert(Random.Range(0, order.Count), "base");
  53. order.Insert(Random.Range(0, order.Count), "hat");
  54. order.Insert(Random.Range(0, order.Count), "eye");
  55. order.Insert(Random.Range(0, order.Count), "top");
  56. order.Insert(Random.Range(0, order.Count), "bottom");
  57. }
  58. public bool CheckChild(GameObject _child)
  59. {
  60. if (_child == child)
  61. {
  62. return true;
  63. }
  64. else
  65. {
  66. return false;
  67. }
  68. }
  69. public Texture GiveDetails(GameObject _child)
  70. {
  71. for (int i = 0; i < order.Count; i++)
  72. {
  73. switch (order[i]){
  74. case "base":
  75. if (child.GetComponent<Randomizer>().baseObj.GetComponent<MeshRenderer>().material.mainTexture != baseVis)
  76. {
  77. return baseVis;
  78. }
  79. break;
  80. case "hat":
  81. if (child.GetComponent<Randomizer>().hatObj.GetComponent<MeshRenderer>().material.mainTexture != hatVis)
  82. {
  83. return hatVis;
  84. }
  85. break;
  86. case "eye":
  87. if (child.GetComponent<Randomizer>().eyeObj.GetComponent<MeshRenderer>().material.mainTexture != eyeVis)
  88. {
  89. return eyeVis;
  90. }
  91. break;
  92. case "top":
  93. if (child.GetComponent<Randomizer>().topObj.GetComponent<MeshRenderer>().material.mainTexture != topVis)
  94. {
  95. return topVis;
  96. }
  97. break;
  98. case "bottom":
  99. if (child.GetComponent<Randomizer>().bottomObj.GetComponent<MeshRenderer>().material.mainTexture != bottomVis)
  100. {
  101. return bottomVis;
  102. }
  103. break;
  104. default:
  105. break;
  106. }
  107. }
  108. return null;
  109. }
  110. private void OnTriggerEnter(Collider other)
  111. {
  112. if (other.gameObject.tag == "child")
  113. {
  114. if (CheckChild(other.gameObject))
  115. {
  116. //this is the correct child
  117. }
  118. else
  119. {
  120. Texture _displayGraphic = GiveDetails(other.gameObject);
  121. //display the display graphic
  122. parentDialougeObj.GetComponent<MeshRenderer>().material.mainTexture = _displayGraphic;
  123. }
  124. }
  125. }
  126. }