Search Unity

Touche marches pas

Discussion in '2D' started by SunSet_Zyco, Nov 10, 2019.

  1. SunSet_Zyco

    SunSet_Zyco

    Joined:
    Nov 10, 2019
    Posts:
    3
    Hello, jsuis un mec random qui essaie de faire des jeux, donc je suis assé amateur ^^

    Je suis un tuto pour mon 1er jeu pour avoir les bases pour créer mon propre jeu solo plus tard, et au fur et a mesure que j'avance, tout marches mais il y a des défaillances, au début ma touche espace marchais pour sauter, et maintenant, elle ne marches plus, j'aurais besoin d'aide, voici le code de mon perso :

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;



    public class CharacBehavior : MonoBehaviour {


    public Rigidbody2D rb;

    public float vitesse;

    public float maxjump;

    private bool isGrounded = false;


    // Start is called before the first frame update

    void Start() {
    SetVelocity(vitesse,0);
    }



    // Update is called once per frame

    void Update() {
    if(Input.GetKeyDown("space") && isGrounded == true){

    Jump();

    }


    void Jump(){

    rb.velocity += new Vector2(0,maxjump);

    }

    }

    void OnCollisionEnter2D(Collision2D col){

    if(col.gameObject.CompareTag("Ground")){

    isGrounded = true;

    }

    }

    void OnCollisionExit2D(Collision2D col){

    if(col.gameObject.CompareTag("Ground")){

    isGrounded = false;

    }

    }
    void SetVelocity(float xVelocity, float yVelocity){
    rb.velocity = new Vector2(0, 0);
    rb.velocity += new Vector2(xVelocity, yVelocity);
    }

    void OnTriggerEnter2D(Collider2D col){
    if(col.gameObject.CompareTag("Obstacle")){
    StartCoroutine(ObstacleFind());
    }
    }
    IEnumerator ObstacleFind(){
    yield return new WaitForSeconds (0.1f);
    SetVelocity(vitesse/2, 0);
    yield return new WaitForSeconds (0.5f);
    SetVelocity(vitesse, 0);
    }

    }

    Merci d'avance,

    Cordialement
     
  2. SunSet_Zyco

    SunSet_Zyco

    Joined:
    Nov 10, 2019
    Posts:
    3
    Prob réglé, le prob été que le maxjump a été set automatiquement par je sais pas quel magie sur 0