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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question pls i need help im new and im stuck with this jump script for 2 days

Discussion in 'Scripting' started by DashingMortis, Jun 10, 2020.

  1. DashingMortis

    DashingMortis

    Joined:
    Jun 1, 2020
    Posts:
    13
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class jumpBOIpls : MonoBehaviour
    6. {
    7.     public float jumpHeight;
    8.     private bool isJumping = false;
    9.     private Rigidbody2D _rigidBody2D;
    10.     public string strTag;
    11.  
    12.     [SerializeField]
    13.     KeyCode jUMP;
    14.  
    15.     private void Awake()
    16.     {
    17.         _rigidBody2D = GetComponent<Rigidbody2D>();
    18.     }
    19.     private void Update()
    20.     {
    21.         if (Input.GetKey(jUMP) && !isJumping)
    22.         {
    23.             _rigidBody2D.AddForce(Vector2.up * jumpHeight);
    24.             isJumping = true;
    25.         }
    26.     }
    27.  
    28.     private void OnCollisionEnter2D(Collision2D collision)
    29.     {
    30.         if(collision.collider.tag == strTag)
    31.         {
    32.             isJumping = false;
    33.         }
    34.     }
    35. }
    36. // me : PLEASE JUST WORK FOR ONCE!!!  my code : no...
    37.  
    pls pls pls pls pls
     
  2. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    try this
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class jumpBOIpls : MonoBehaviour
    6. {
    7.     public float jumpHeight;
    8.     private bool isJumping = false;
    9.     private Rigidbody2D _rigidBody2D;
    10.     public string strTag;
    11.  
    12.     [SerializeField]
    13.     KeyCode jUMP;
    14.  
    15.     private void Awake()
    16.     {
    17.         _rigidBody2D = GetComponent<Rigidbody2D>();
    18.     }
    19.     private void Update()
    20.     {
    21.         if (Input.GetKeyDown(KeyCode.Space) && !isJumping)
    22.         {
    23.             _rigidBody2D.AddForce(Vector2.up * jumpHeight);
    24.             isJumping = true;
    25.         }
    26.     }
    27.  
    28.     private void OnCollisionEnter2D(Collision2D collision)
    29.     {
    30.         if(collision.collider.tag == strTag)
    31.         {
    32.             isJumping = false;
    33.         }
    34.     }
    35. }
    36. // me : PLEASE JUST WORK FOR ONCE!!!  my code : no...
    37.  
     
  3. DashingMortis

    DashingMortis

    Joined:
    Jun 1, 2020
    Posts:
    13
    wat is the difference?