// Start is called before the first frame update void Start() { item1Location = item1.transform; item2Location = item2.transform; item1.SetActive(false); item2.SetActive(false); demoScript = FindObjectOfType <BasicDemoScript>(); }
/// <summary> /// Open the box. /// </summary> public void Open() { //see if the demo script is ready to open chest BasicDemoScript demoScript = FindObjectOfType <BasicDemoScript>(); if (!demoScript.readyToOpenChest) { return; } // avoid opening when it's already open if (isOpen) { return; } isOpen = true; Debug.Log("Attempting to open chest"); // play the open animation if (animator) { animator.Play("Open"); } // calculates the chance of each loot inside the box // and pupulates a list with all received treasures // creates a temp list to store the earned items List <GameObject> loots = new List <GameObject>(); // check each prize in this box foreach (Loot loot in boxContents) { // roll the dice for a chance to win float chance = UnityEngine.Random.Range(0.0f, 1.0f); // if win add the item to the temp list if (loot.dropChance >= chance) { // Debug.Log("You got " + loot.loot.name); loots.Add(loot.loot); } } // empty the box boxContents.Clear(); // calls the OnBoxOpen event and deliver the // earned GameObjects on temp list OnBoxOpen?.Invoke(loots.ToArray()); }
// Update is called once per frame void Update() { BasicDemoScript demoScript = FindObjectOfType <BasicDemoScript>(); float distanceToWaypoint = Vector3.Distance(this.gameObject.transform.position, Camera.main.transform.position); if (distanceToWaypoint < 1.5 && InFrontOfCamera(Camera.main, this.gameObject) && demoScript.searching && !objectFound) { objectFound = true; demoScript.objectsFound++; Debug.Log(this.gameObject.transform.GetChild(0).name); if (this.gameObject.transform.GetChild(0).name.Contains("ChestContainer")) { Debug.Log("Found Chest Container"); ChestManager chestManager = this.gameObject.transform.GetChild(0).GetComponent <ChestManager>(); Debug.Log("Chest Manager"); chestManager.found = true; Debug.Log("chestmanager found"); return; } InventoryManager inventoryManager = FindObjectOfType <InventoryManager>(); if (this.gameObject.transform.GetChild(0).name.Contains("KeyContainer")) { //inventoryManager.KeyFound(); } else if (this.gameObject.transform.GetChild(0).name.Contains("ShovelContainer")) { //inventoryManager.ShovelFound(); } Animator[] animators = this.gameObject.GetComponentsInChildren <Animator>(); foreach (Animator a in animators) { a.enabled = true; } var renderers = this.gameObject.GetComponentsInChildren <Renderer>(); foreach (Renderer r in renderers) { r.enabled = true; } } }