Playing animation once confusion.

Hey guys - here with my nightly sleep cap learning questions. Most things went smooth today in regards to learning, and I bypassed this problem after spending 30 minutes on it so I could post this up later to understand better what is going on. As always I consulted refs, and did searches - I found people having the same issue, but the solutions given to them did not work for me. Plus I’ve got a few general questions.

Below is the snip of code I’m having a issue with. A tree falling once. Only showing a small portion of code and I’ll state whats happening (using debugs)

Using endTime to kick off when the tree will fall after the player starts to chop the tree. Counts down fine - doesn’t play the fallen animation until its complete. Debugging to make sure that fallen stays false in the upper part of code and it is. Once the time limit hits 0, and false is not equal to true (I only want to poke my head in here once) but for whatever reason the code keeps poking its head into if (timeLeft == 0 && !fallen) - I’ve tried several things as always, fallen != true, changing values around, I think I have this right and its not just that time of night where I become even more worthless then normal…

Also - I’m turning into a if nester - is this bad or good? Just looking for opinions. Any comments on how to improve my typing habits and so forth are also welcome. I’m use to abuse.

	void Update()
	{
		if (playerScript.startChop == true)
		{
			Debug.Log(fallen);
			Debug.Log("startChop fallen");
			fallen = false;
			animation.CrossFade("Axe_Strike");
			float timeLeft = endTime - Time.time;
			if (timeLeft < 0) timeLeft = 0;
				if (timeLeft == 0 && !fallen)
				{	
					animation.wrapMode = WrapMode.Once;
					animation.Play ("Tree_Fall");
					fallen = true;
					Debug.Log(fallen);
					Debug.Log("from fall once");
				}

			

		}
	}

Thanks guys.

It seems that your code keeps fallen at false, even when the timeLeft = 0. I suggest you edit the fallen = false to this

if(timeLeft < 0) {
    fallen = false;
}

This ought to keep the fallen true after your time has expired.

~ExplodingCookie

Well woke up this morning and went right at it - ended up with

enter code here	void Update()
	{
		if (playerScript.startChop == true)
		{
			
			
			if (fallen == false)
			{
				animation.CrossFade("Axe_Strike");
			}
			float timeLeft = endTime - Time.time;
			if (timeLeft < 0)
			{ 
				timeLeft = 0;
				if (timeLeft == 0 && !fallen)
				{	
					animation.CrossFade("Tree_Fall");
					fallen = true;
					Debug.Log(fallen);
					Debug.Log("TRIGGERED");
				}

			}

		}
	}

After a few minutes, then checked the board here. Man - sleep does wonders.