Bonjour,
Merci mais je m'en sors pas ^^
Visiblement ça me permet d'obtenir des stats sur les animations mais je n'arrive pas à trouver le code exact pour que ça marche.
Il me faudrait un code genre :
if (Input.GetMouseButtonDown(0) && !(Tel animation est joué ou tel animation Frame >1)
Mais je ne trouve pas le code exact.
Je précise que j'ai déjà dans mon Void Start : anim = GetComponent<Animator>();
Je vous mets mon code actuel complet (mais je vous préviens ça va piquer les yeux de certains, beaucoup de bidouillage :p ) Mais ça marche à part mon souci bien entendu...
Code : Tout sélectionner
public class PlayerController : MonoBehaviour
{
public int speed = 5;
public int speedrun = 10;
public int speedrawl = -5;
public int coefRot = 200;
private Animator anim;
public Vector3 jumpSpeed;
BoxCollider playerCollider;
void Start()
{
anim = GetComponent<Animator>();
playerCollider = gameObject.GetComponent<BoxCollider>();
}
bool IsGrounded()
{
Vector3 dwn = transform.TransformDirection(Vector3.down);
return (Physics.Raycast(transform.position, dwn, 1));
}
void Update()
{
// Déplacement
if (Input.GetKey(KeyCode.C) && Input.GetAxis("Vertical") > 0)
{
transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * speedrawl * Time.deltaTime);
}
if (Input.GetKey(KeyCode.LeftControl) && Input.GetAxis("Vertical") > 0 &&! Input.GetKey(KeyCode.C))
{
transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * speedrun * Time.deltaTime);
}
if (!Input.GetKey(KeyCode.LeftControl) && Input.GetAxis("Vertical") > 0 && !Input.GetKey(KeyCode.C))
{
transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * speed * Time.deltaTime);
}
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * coefRot * Time.deltaTime);
if (Input.GetAxis("Vertical") > 0 && !Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.Space) && IsGrounded())
{
anim.SetBool("Walk", true);
anim.SetBool("Run", false);
anim.SetBool("Recul", false);
anim.SetBool("Baissé", false);
}
//run
if (Input.GetAxis("Vertical") > 0 && Input.GetKey(KeyCode.LeftShift))
{
anim.SetBool("Walk", false);
anim.SetBool("Run", true);
anim.SetBool("Recul", false);
anim.SetBool("Baissé", false);
}
if (Input.GetAxis("Vertical") > 0 && Input.GetKey(KeyCode.C))
{
anim.SetBool("Walk", false);
anim.SetBool("Run", false);
anim.SetBool("Recul", false);
anim.SetBool("Baissé", true);
}
//idle
if (Input.GetAxis("Vertical") == 0 && !Input.GetKey(KeyCode.Z) && !Input.GetKey(KeyCode.S) && IsGrounded())
{
anim.SetBool("Walk", false);
anim.SetBool("Run", false);
anim.SetBool("Recul", false);
anim.SetBool("Baissé", false);
}
if (Input.GetAxis("Vertical") < 0)
{
anim.SetBool("Recul", true);
anim.SetBool("Walk", false);
anim.SetBool("Run", false);
anim.SetBool("Baissé", false);
}
if (Input.GetKeyDown(KeyCode.Space) && IsGrounded() && (Input.GetAxis("Vertical") >= 0) && !Input.GetKey(KeyCode.C))
{
Vector3 v = gameObject.GetComponent<Rigidbody>().velocity;
v.y = jumpSpeed.y;
gameObject.GetComponent<Rigidbody>().velocity = jumpSpeed;
anim.SetTrigger("Jump");
}
if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.C))
{
anim.SetTrigger("Attack 1");
Debug.Log(" clic gauche souris !");
}
if (Input.GetMouseButtonDown(1) && !Input.GetKey(KeyCode.C))
{
anim.SetTrigger("Attack 2");
Debug.Log(" clic droit souris !");
}
if (Input.GetMouseButtonDown(2) && !Input.GetKey(KeyCode.C))
{
anim.SetTrigger("Attack 3");
Debug.Log(" clic milieu souris !");
}
if (Input.GetKeyDown(KeyCode.F) && !Input.GetKey(KeyCode.C))
{
anim.SetTrigger("Block");
}
}
}