hello guys , i am new to the world of unity programming , as i am new to programmation , and i was planning to create a small 2D game , but i already have a problem :
so i a am using 2D toolkit pakage alsow ; i have an animated sprit as my main character wich i was aiming to controle (make him slide left and right on the X axis) , with the arrow keys via a script a wrote, the sprit plays a small animation called idle at the start , and i wanted to be able to switch the idle animation with a walking animation as the spriit goes left or rigth… here is the very humble code i managed to produce :
using UnityEngine;
using System.Collections;
public class changeanim : MonoBehaviour {
tk2dSpriteAnimator animator;
public float moveSpeed = 10f;
// Use this for initialization
void Start () {
animator = GetComponent();
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.LeftArrow)){
transform.Translate(Vector3.left * moveSpeed * Time.deltaTime);
animator.Play (“joewalk”);}
if(Input.GetKey(KeyCode.RightArrow)){
transform.Translate(Vector3.right * moveSpeed * Time.deltaTime);
transform.Rotate(Vector3.Scale); }
}
}
so with that i am able to displace the main character along the X axis (left and right) and play a walk animation when he goes left , but i have 2 problemes !!
the first is that when the left walk animation(“joewalk”) is played , i get stuck with the walk animation , it dont go back to the idle animation !
and the second problem is that when i go to the left my character is facing left , cause thats how he starts , but i want him to face to the right when i click the rigth arrow and i dont know how to do that
please help me if you know the solution , i am here pulling my hair for 3 hours with that :-[