Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Bug my character does not jump

Discussion in 'Animation' started by YYURIY, Dec 26, 2022.

  1. YYURIY

    YYURIY

    Joined:
    Dec 26, 2022
    Posts:
    2
    my code
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class CharacterController : MonoBehaviour
    {
    Rigidbody2D rb;

    public float jumpForce, speed;
    public Transform groundCheck;
    public LayerMask layerGround;
    public float horizontalspeed;
    // Start is called before the first frame update
    void Start()
    {
    rb = GetComponent<Rigidbody2D>();
    Input.multiTouchEnabled = true;
    }

    public void LeftButtonDown()
    {
    speed = -horizontalspeed;
    }

    public void RightButtonDown()
    {
    speed = horizontalspeed;
    }

    public void Stop()
    {
    speed = 0;
    }

    public void Jump()
    {
    if (Physics2D.OverlapCircle(groundCheck.position, 0.1f, layerGround))
    rb.velocity = new Vector2(rb.velocity.x, jumpForce);
    }

    // Update is called once per frame
    void FixedUpdate()
    {
    rb.velocity = new Vector2(speed, rb.velocity.y);
    }

    }
    the character only moves left and right
     
  2. YYURIY

    YYURIY

    Joined:
    Dec 26, 2022
    Posts:
    2