Advertisement
Guest User

Untitled

a guest
Mar 21st, 2023
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5. using UnityEngine.Rendering.PostProcessing;
  6. using UnityEngine.Audio;
  7.  
  8. [RequireComponent(typeof(ItemConfig))]
  9. public class GameManager : MonoBehaviour
  10. {
  11.  
  12. [Header("Stats")]
  13. public int itemsCollected = 0;
  14. public int trappedTreeMax;
  15.  
  16. [Header("References")]
  17. public GameObject treeParent;
  18. [SerializeField] GameObject itemParent;
  19. [SerializeField] GameObject prefabTrappedTree;
  20. [SerializeField] AudioManager audioManager;
  21. [SerializeField] AudioMixer mixer;
  22. [SerializeField] Sprite[] itemSprites;
  23. [SerializeField] ItemConfig itemConfig;
  24. [SerializeField] Camera cam;
  25. [SerializeField] SpriteRenderer ritualRenderer;
  26. [SerializeField] Sprite[] ritualSprites;
  27.  
  28. private void Start()
  29. {
  30. audioManager.Play("Ambient");
  31.  
  32.  
  33. int treeParentChildCount = treeParent.transform.childCount;
  34.  
  35. int itemChildCount = itemParent.transform.childCount - 1;
  36.  
  37. cam = Camera.main;
  38.  
  39. Player.spit += playerGotSpit;
  40. Player.ritualItem += playerPlacedItemInRitual;
  41.  
  42.  
  43. //Setup
  44. for (int i = 0; i < treeParentChildCount; i++)
  45. {
  46. int treeChildCount = treeParent.transform.GetChild(i).transform.childCount;
  47.  
  48. for (int b = 0; b < trappedTreeMax; b++)
  49. {
  50. GameObject replace = treeParent.transform.GetChild(i).transform.GetChild(Random.Range(0, treeChildCount)).gameObject;
  51. GameObject a = Instantiate(prefabTrappedTree);
  52. a.transform.position = replace.transform.position;
  53. replace.transform.position = new Vector3(100, 100);
  54. replace.transform.parent = null;
  55. a.transform.parent = treeParent.transform.GetChild(i);
  56. }
  57.  
  58. for (int j = 0; j < 2; j++)
  59. {
  60. GameObject item = itemParent.transform.GetChild(Random.Range(0, itemChildCount)).gameObject;
  61.  
  62. print("Item Name: " + item.gameObject.name);
  63.  
  64. itemConfig.ItemConfiguration(item);
  65.  
  66. item.transform.parent = null;
  67.  
  68. bool safePlace = false;
  69. Collider2D results = Physics2D.OverlapCircle(item.transform.position, 2, LayerMask.NameToLayer("TrappedTrees"));
  70.  
  71. while (safePlace == false)
  72. {
  73. item.transform.position = treeParent.transform.GetChild(i).transform.GetChild(Random.Range(0, treeChildCount)).transform.position;
  74. item.transform.position += new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(-0.5f, -1.1f), 0);
  75. if (results == null)
  76. {
  77. safePlace = true;
  78. }
  79. }
  80. itemChildCount--;
  81. }
  82. }
  83. }
  84.  
  85. void playerGotSpit(bool isTrue)
  86. {
  87.  
  88. }
  89.  
  90. void playerPlacedItemInRitual()
  91. {
  92. itemsCollected += 1;
  93. ritualRenderer.sprite = ritualSprites[itemsCollected];
  94. }
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement