I am working on a 2D game in which dungeons are generated in runtime. Now each room in the dungeon can have door at North, South, East or West randomly.
If the player is exiting Room1 from South, the next scene should have the player in Room2 near the North door with Direction facing the room.
I am able to achieve all the steps above except facing the room dynamically.
If player exits Room1 from east, player should be facing east of Room2 and so on.
I have Controller created for movement with a Default state But right now the Default state has a Motion that is assigned from inspector.
How do I assign Motion to this Default on runtime? I have tried AnimatorOverrideController but there is no change in Motion field.
The Controller:
My PlayerMovement script handles the animation of the Player
public class PlayerMovement : MonoBehaviour
{
public AnimationClip[] clip;
protected AnimatorOverrideController animatorOverrideController;
void Start()
{
dir = GetDirection();
Debug.Log("Dir is " + dir);
animatorOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
animator.runtimeAnimatorController = animatorOverrideController;
animatorOverrideController["Default"] = clip[dir];
}
}
Player inspector:
Thanks in advance.