Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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