Je viens avec une petite interrogation j'ai dans le code qui suit mis un input Mousebutton ( clique gauche ) mais si je lui joint l'animation de tir elle boucle jusqu'a ce que je "reclique" sur la touche alors que je veux juste la faire jouer une seul fois et bien sur qu'il joue l'animation uniquement quand je clique.
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
public class PlayerControl : MonoBehaviour {
//variable de movement
public float maxSpeed;
//variable de saut
bool grounded = false;
float CheckSolRadius = 0.2f;
public LayerMask SolLayer;
public Transform CheckSol;
public float jumpHeight;
//variable de transformation
Rigidbody2D RB;
Animator anim;
bool facingRight;
//Pour tirer
public Transform gunTip;
public GameObject bullet;
public float fireRate = 0.5f;
float nextFire = 0f;
// Use this for initialization
void Start () {
RB = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
facingRight = true;
}
// Update is called once per frame
void Update(){
if(grounded && Input.GetAxis("Jump")>0){
grounded = false;
anim.SetBool("touchSol",grounded);
RB.AddForce(new Vector2(0,jumpHeight));
}
//Player tire
if (Input.GetMouseButtonDown (0)) fireBullet ();{
anim.SetBool ("Shoot",true);
}
}
void FixedUpdate () {
//Check si on est au sol - si non on tombe
grounded = Physics2D.OverlapCircle(CheckSol.position,CheckSolRadius,SolLayer);
anim.SetBool("touchSol",grounded);
anim.SetFloat ("JumpHeight", RB.velocity.y);
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("Speed", Mathf.Abs (move));
RB.velocity = new Vector2 (move * maxSpeed, RB.velocity.y);
if (move > 0 && !facingRight) {
flip ();
} else if(move<0&&facingRight){
flip ();
}
}
void flip(){
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
void fireBullet(){
if (Time.time > nextFire) {
nextFire = Time.time + fireRate;
if (facingRight) {
Instantiate (bullet, gunTip.position, Quaternion.Euler (new Vector3 (0, 0, 0)));
} else if (!facingRight) {
Instantiate (bullet, gunTip.position, Quaternion.Euler (new Vector3 (0, 0, 180f)));
}
}
}
}
Je vous remercie d'avance pour le temps que vous m'accorder.
Nicolas V.