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.

133 lines
4.2 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. [ContextMenu("Get Random Child")]
  22. public void GetRandomChild()
  23. {
  24. bool _validChild = false;
  25. while (!_validChild)
  26. {
  27. int _childIndex = Random.Range(0, babySpawner.transform.childCount);
  28. child = babySpawner.transform.GetChild(_childIndex).gameObject;
  29. if (otherParent.child != null)
  30. {
  31. if (child != otherParent.child)
  32. {
  33. //this prevents both parents asking for the same child
  34. _validChild = true;
  35. }
  36. }
  37. }
  38. Randomizer _childRandomizer = child.GetComponent<Randomizer>();
  39. baseVis = _childRandomizer.baseObj.GetComponent<MeshRenderer>().material.mainTexture;
  40. hatVis = _childRandomizer.hatObj.GetComponent<MeshRenderer>().material.mainTexture;
  41. eyeVis = _childRandomizer.eyeObj.GetComponent<MeshRenderer>().material.mainTexture;
  42. topVis = _childRandomizer.topObj.GetComponent<MeshRenderer>().material.mainTexture;
  43. bottomVis = _childRandomizer.bottomObj.GetComponent<MeshRenderer>().material.mainTexture;
  44. order.Insert(Random.Range(0, order.Count), "base");
  45. order.Insert(Random.Range(0, order.Count), "hat");
  46. order.Insert(Random.Range(0, order.Count), "eye");
  47. order.Insert(Random.Range(0, order.Count), "top");
  48. order.Insert(Random.Range(0, order.Count), "bottom");
  49. }
  50. public bool CheckChild(GameObject _child)
  51. {
  52. if (_child == child)
  53. {
  54. return true;
  55. }
  56. else
  57. {
  58. return false;
  59. }
  60. }
  61. public Texture GiveDetails(GameObject _child)
  62. {
  63. for (int i = 0; i < order.Count; i++)
  64. {
  65. switch (order[i]){
  66. case "base":
  67. if (child.GetComponent<Randomizer>().baseObj.GetComponent<MeshRenderer>().material.mainTexture != baseVis)
  68. {
  69. return baseVis;
  70. }
  71. break;
  72. case "hat":
  73. if (child.GetComponent<Randomizer>().hatObj.GetComponent<MeshRenderer>().material.mainTexture != hatVis)
  74. {
  75. return hatVis;
  76. }
  77. break;
  78. case "eye":
  79. if (child.GetComponent<Randomizer>().eyeObj.GetComponent<MeshRenderer>().material.mainTexture != eyeVis)
  80. {
  81. return eyeVis;
  82. }
  83. break;
  84. case "top":
  85. if (child.GetComponent<Randomizer>().topObj.GetComponent<MeshRenderer>().material.mainTexture != topVis)
  86. {
  87. return topVis;
  88. }
  89. break;
  90. case "bottom":
  91. if (child.GetComponent<Randomizer>().bottomObj.GetComponent<MeshRenderer>().material.mainTexture != bottomVis)
  92. {
  93. return bottomVis;
  94. }
  95. break;
  96. default:
  97. break;
  98. }
  99. }
  100. return null;
  101. }
  102. private void OnTriggerEnter(Collider other)
  103. {
  104. if (other.gameObject.tag == "child")
  105. {
  106. if (CheckChild(other.gameObject))
  107. {
  108. //this is the correct child
  109. }
  110. else
  111. {
  112. Texture _displayGraphic = GiveDetails(other.gameObject);
  113. //display the display graphic
  114. }
  115. }
  116. }
  117. }