Je suis en trains de créer un jeu 2D unity en C#, et je rencontre un souci pour l'animation, pouvez vous m'aider svp.
mon animation de marche ne se déclanche pas, pourquoi ?
voici mon code :
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mage : MonoBehaviour
{
float speed = 0.1f;
public float h, v;
public Animation anim;
void Start()
{
anim = GetComponent<Animation>();
}
// Update is called once per frame
void Update()
{
h = Input.GetAxis("Horizontal") * speed;
v = Input.GetAxis("Vertical") * speed;
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
transform.localScale = new Vector2(-1, 1);
anim.Play("marche");
}
else if (Input.GetKey(KeyCode.RightArrow))
{
transform.localScale = new Vector2(1, 1);
}
transform.Translate(h, v, 0);
}
}