I have a animation that plays, and I run the function DisablePlayer when the animation ends, but when I renable the player its still stuck on the last frame of the animation, i tried stuuf but its not working, heres my code
public void DisablePlayer()
{
gameObject.SetActive(false);
}
void DestroyAllObjects()
{
GameObject[] objects = GameObject.FindGameObjectsWithTag("Asteroid");
foreach (GameObject obj in objects)
{
Destroy(obj);
}
}
public void EnablePlayer()
{
gameObject.SetActive(true);
}
}
If I’m understanding this question correctly, you call EnablePlayer() manually and want it to change the state of the AnimatorController there, correct? If so, you can call gameObject.GetComponent<Animator>().Play("InitialStateNameWhateverYouCalledItInYourController");
It isnt working, I think because I have nothing set for the default animation so it doesnt know what to play, because its still stuck on the last frame.
Sounds like you wrote a bug… and that means… time to start debugging!
First, work through the animation stuff I already posted above.
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.
Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.
Screenshot your animator controller and I can tell you, but it’s just whatever is the default state. You can’t have an animator controller without one. Or is this using the legacy animation component?