can you help with my code?

using UnityEngine;
using System.Collections;

public class ControladorPersonaje : MonoBehaviour {
   
    public float fuerzaSalto = 100f;

    public float distanceTraveled;
    //public TextMesh marcador;

   
    private bool enSuelo = true;
    public Transform comprobadorSuelo;
    private float comprobadorRadio = 0.07f;
    public LayerMask mascaraSuelo;
   
    private Animator animator;
   
    private bool corriendo = false;
    public float velocidad = 1f;
   
    void Awake(){
        animator = GetComponent<Animator>();
    }

    void Start () {
        NotificationCenter.DefaultCenter().AddObserver(this, "PersonajeHaMuerto");

    }
   
    void PersonajeHaMuerto(Notification notificacion){
        if(distanceTraveled > EstadoJuego.estadoJuego.puntuacionMaxima){

            EstadoJuego.estadoJuego.puntuacionMaxima = distanceTraveled;
            EstadoJuego.estadoJuego.Guardar();

        }
    }
   
    void FixedUpdate(){
        if(corriendo){
            rigidbody2D.velocity = new Vector2(velocidad, rigidbody2D.velocity.y);
        }
        animator.SetFloat("VelX", rigidbody2D.velocity.x);
        enSuelo = Physics2D.OverlapCircle(comprobadorSuelo.position, comprobadorRadio, mascaraSuelo);
        animator.SetBool("isGrounded", enSuelo);
    }

    private void GameStart () {
       
        distanceTraveled = 0f;
        GUIManager.SetDistance (distanceTraveled);

    }

    //void ActualizarMarcador(){
    //    marcador.text = distanceTraveled.ToString();
    //}

    // Update is called once per frame
    void Update () {

        distanceTraveled = transform.localPosition.x;
        GUIManager.SetDistance(distanceTraveled);

        if(Input.GetMouseButtonDown(0)){
            if(corriendo){
                // Hacemos que salte si puede saltar
                if(enSuelo){
                    audio.Play();
                    rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, fuerzaSalto);
                    //rigidbody2D.AddForce(new Vector2(0, fuerzaSalto));
                }
            }else{
                corriendo = true;
                NotificationCenter.DefaultCenter().PostNotification(this, "PersonajeEmpiezaACorrer");
            }
        }
    }
}

i want that my player have 3 jumps but i dont know

using UnityEngine;
using System.Collections;

public class ControladorPersonaje : MonoBehaviour {
  
    public float fuerzaSalto = 100f;

    public float distanceTraveled;
    //public TextMesh marcador;
  
    private bool enSuelo = true;
    public Transform comprobadorSuelo;
    private float comprobadorRadio = 0.07f;
    public LayerMask mascaraSuelo;

    // Y U NO Speak English?
    public int jumpsHave = 3;

    private Animator animator;
  
    private bool corriendo = false;
    public float velocidad = 1f;
  
    void Awake(){
        animator = GetComponent<Animator>();
    }

    void Start () {
        NotificationCenter.DefaultCenter().AddObserver(this, "PersonajeHaMuerto");

    }
  
    void PersonajeHaMuerto(Notification notificacion){
        if(distanceTraveled > EstadoJuego.estadoJuego.puntuacionMaxima){

            EstadoJuego.estadoJuego.puntuacionMaxima = distanceTraveled;
            EstadoJuego.estadoJuego.Guardar();

        }
    }
  
    void FixedUpdate(){
        if(corriendo){
            rigidbody2D.velocity = new Vector2(velocidad, rigidbody2D.velocity.y);
        }
        animator.SetFloat("VelX", rigidbody2D.velocity.x);
        enSuelo = Physics2D.OverlapCircle(comprobadorSuelo.position, comprobadorRadio, mascaraSuelo);
        animator.SetBool("isGrounded", enSuelo);
    }

    private void GameStart () {
      
        distanceTraveled = 0f;
        GUIManager.SetDistance (distanceTraveled);

    }

    //void ActualizarMarcador(){
    //    marcador.text = distanceTraveled.ToString();
    //}

    // Update is called once per frame
    void Update () {

        distanceTraveled = transform.localPosition.x;
        GUIManager.SetDistance(distanceTraveled);

        if(Input.GetMouseButtonDown(0)){
            if(corriendo){
                // Hacemos que salte si puede saltar
                if(enSuelo && jumpsHave > 0){
                    jumpsHave--;
                    audio.Play();
                    rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, fuerzaSalto);
                    //rigidbody2D.AddForce(new Vector2(0, fuerzaSalto));
                }
            }else{
                corriendo = true;
                NotificationCenter.DefaultCenter().PostNotification(this, "PersonajeEmpiezaACorrer");
            }
        }
    }
}

WITH THIS CODE WHat can i do?

i do it and i dont see the diference of my old code…

you can only jump 3 times now
or isnt that what you wanted?

i want… it is a android game… and endleess runer… and it spawns 3 objcts in diferrents heights… and i need 3 differents jump … the height of jumps is how you hold touch the screen

You should learn how to write posts…

Here is an idea how to do it:
detect touch on display and save the time when you touch in a variable. when you end the touch you have to compare the time with the time you saved at the beginning of touch. Now you have to say for example:

if timeDifference<= 0.3f then jump(0.5f)
else if timeDifference <= 0.6f && timeDifference > 0.3f then jump(0.75f)
else if timeDifference > 0.6f then jump(1f)

and the code?

ratg97, this community want to help… but in order to do it, you must show some compromise.
You can’t ask for help, and after get the ideas, ask for the code.

Try to do it yourself; this will enforce us to guide you if you get stuck.

1 Like

uppppppp

Your not going to get much help if your going to be immature and repost the same thing in 4 different topics. Nore are you going to get people to write your code for you.

Just try it yourself and come back if you get stuck for a while, and ask for help about that problem your stuck on, not on the script as a whole.