The player of my game is going to be a cube, so I made an Idle animation and Walking animation. The idle animation works fine because it stays in one place but when the walking animation is triggered my player walks and when the animation is done my player positions gets reset to its original starting position. (Game is for Android) So how to I make my player stay at the same position it is when the animation is finished? (The coding works 100% fine or is there something I did wrong)
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityEngine.EventSystems;
public class Players : MonoBehaviour
{
public Rigidbody player;
Animator anim;
public static float ySpeed = 0;
public static float xSpeed = 0;
public static float zSpeed = 0;
private void Awake()
{
}
private void Start()
{
anim = GetComponent<Animator>();
}
private void Update()
{
}
private void FixedUpdate()
{
player.velocity = new Vector3(xSpeed, ySpeed, zSpeed);
}
#region Movement
public void MoveLeft(string moveleft)
{
anim.SetBool("Idle", false);
anim.SetBool("Walk", true);
xSpeed = 3;
}
public void MoveRight(string moveright)
{
anim.SetBool("Idle", false);
anim.SetBool("Walk", true);
xSpeed = -3;
}
public void MoveForward(string moveforward)
{
anim.SetBool("Idle", false);
anim.SetBool("Walk", true);
zSpeed = -3;
}
public void MoveBackward(string movebackward)
{
anim.SetBool("Idle", false);
anim.SetBool("Walk", true);
zSpeed = 3;
}
public void StopMove(string stopmove)
{
anim.SetBool("Idle", true);
anim.SetBool("Walk", false);
zSpeed = 0;
xSpeed = 0;
}
public void OnPointerEnter(PointerEventData EventData)
{
}
public void OnPointerExit(PointerEventData EventData)
{
}
public void OnPointerDown(PointerEventData EventData)
{
}
public void OnPointerUp(PointerEventData EventData)
{
}
#endregion
}