IEnumerator Dig(string type, float duration) { //BEGINNING-------------------------------------------------------- PlayerController.controlsAble = false; anim.SetTrigger("DigTrigger"); ParticleSystem instDigFX = Instantiate(digFX, transform.position, Quaternion.identity); //Instantiate FX Destroy(instDigFX, duration); Coroutine soundCo = StartCoroutine(DiggingSound(duration)); switch (type) { case "Spot": Debug.Log("You digged out the " + newSpotManager.type + " number " + newSpotManager.part); Camera.main.GetComponent <InventoryManager> ().playerInventory.AddItem(newSpotManager.type, newSpotManager.part); break; } //DURING yield return(new WaitForSeconds(duration)); //AFTER--------------------------------------------------------------- switch (type) { case "Spot": //PartPreview (newSpotManager.type, newSpotManager.part); //Instantiate canvas with preview of the sk part PartPreviewOverlay(); Destroy(newSpotManager.transform.gameObject); newSpotManager = null; break; case "Baril": newRbBaril.freezeRotation = false; newRbBaril.isKinematic = false; newRbBaril.AddForce(new Vector3(0, 50, 0)); break; case "Palmier": newPalmier.NoixDeCocoFall(); newPalmier = null; break; } anim.SetTrigger("DigOverTrigger"); if (type != "Spot") { PlayerController.controlsAble = true; } }
} //Check l'Input void OnTriggerStay(Collider other) { float distance = Vector3.Distance(other.transform.position, transform.position); //SPOT------------------------------------------------------------------------------------------------ if (other.tag == "Spot" && digInput && distance < 3f) { newSpotManager = other.transform.GetComponent <SpotManager> (); StartCoroutine(Dig("Spot", 1.5f)); digInput = false; } //RUBBLE---------------------------------------------------------------------------------------------- else if (other.tag == "Rubble" && digInput && distance < 6f) { RubbleManager rubMan = other.gameObject.GetComponent <RubbleManager> (); if (rubMan.readyToDig) { rubMan.StartCoroutine("RubbleClear"); PlayerController.controlsAble = false; anim.SetTrigger("DigTrigger"); } digInput = false; } //BARIL------------------------------------------------------------------------------------------ else if (other.tag == "Baril" && digInput && distance < 3.5f && other.GetComponent <Rigidbody>().isKinematic) { newRbBaril = other.GetComponent <Rigidbody>(); StartCoroutine(Dig("Baril", 1f)); digInput = false; } else if (other.tag == "Palmier" && digInput && distance < 3f) { print("nice"); StartCoroutine(Dig("Palmier", 1f)); digInput = false; newPalmier = other.GetComponent <PalmiersScripts> (); } }