If any of the frequenters of the forums happen to drop in on this post; beware I will be having a lot of questions! I'm a new programmer who is interested in game design, and I tend to learn best by 1.) Attempting to problem solve on my own, 2.) Researching the problem 3.) Asking others with more experience for help. I learned how to delay "Die" being called by using invoke; however that doesn't allow time for the animation to process, and there is a quick snap of the screen back to the player's original transform. I am looking for a smoother solution than using invoke to delay death. My code is listed in the files below. My ProcessPlayerDeath function lives within my Game Session/Game Manager Script. And my Die function lives within my player controller script. I'm thinking there may be a way to delay "ProcessPlayerDeath" using transform and that will solve the issue? However I am simply unsure. Thanks in advance for the effort and replies.
atleast coroutines are easy way to add delays https://docs.unity3d.com/ScriptReference/Coroutine.html https://unity3d.com/learn/tutorials/topics/scripting/coroutines
You learn stuff in a nice way, don't forget to add "4) Answer others with less experience". This actually help you a lot to remember what you learnt, and sometimes help you getting a new idea when you are momentally stuck on something. I confirm, coroutines are easy way to add delays. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Testingblabla : MonoBehaviour { IEnumerator DelayedDeath() { Debug.Log("Hero is dying");//Launch the animation and stuffs yield return new WaitForSeconds(5f);//Delay for 5 seconds Debug.Log("Hero is dead");//ProcessPlayerDeath } void Start() { StartCoroutine("DelayedDeath");//The hero starts to die } } You could also, inside the animation, set a function to be called when the animation reaches a certain time. (At the end of your "Die" Animation, for example)
Trying to use code to do it first; and I'm having a problem. As soon as I spawn, it triggers an unstoppable chain of deaths,(which do appear to be spread apart by 2 seconds). I'll post the picture of my code. And in my head it should be working properly, but clearly it isn't. Maybe you could give me a hand? *PS* I attempted putting the "StartCoroutine" line of code within the Start method as well; This yielded the same results as mentioned above.