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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

HELP It says all complier errors have to be fixed before you can enter playmode

Discussion in 'Scripting' started by jakeb2023, Nov 6, 2020.

  1. jakeb2023

    jakeb2023

    Joined:
    Nov 6, 2020
    Posts:
    3
    Please help what is wrong with this script?



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class playermovement : MonoBehaviour{
    6. public float movementSpeed;
    7.     public Rigidbody2D rb;
    8.  
    9.     public float jumpforce =20f;
    10.  
    11.     float mx;
    12.  
    13.     private void Update()  {
    14.         mx = Input.GetAxisRaw("Horizontal");
    15.  
    16.         if (input.GetButtonDown("Jump")) {
    17.             jump();
    18.         }
    19.     }
    20.  
    21.     private void FixedUpdate()  {
    22.         Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);
    23.  
    24.         rb.velocity = movement;
    25.  
    26.     }
    27.  
    28.     void Jump() {
    29.      
    30.         Vector2 movement = new Vector2(rb.velocity.x, jumpforce);
    31.  
    32.         rb.velocity = movement;
    33.     }
    34.  
    35.      
    36. }
    37.  
     

    Attached Files:

  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    For one, you wrote jump() in line 17, but your method is called Jump().

    Not sure why that's not being underlined in red. You may want to fix that.
     
  3. diego-giacomelli

    diego-giacomelli

    Joined:
    Oct 27, 2012
    Posts:
    26
    In addition to the problem on line 17 mentioned by @Yoreki, there is also an error on line 16, since input must be written Input.
     
    Yoreki likes this.
  4. jakeb2023

    jakeb2023

    Joined:
    Nov 6, 2020
    Posts:
    3
    Thank you very much that worked :)