Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Error CS0103 I'm beginner at this. Need help.

Discussion in 'Editor & General Support' started by DiasErik, Jan 24, 2021.

  1. DiasErik

    DiasErik

    Joined:
    Jan 22, 2021
    Posts:
    2
    Hello guys, i wrote a simple script for a 2d character movement, but unity is dropp up the Error cs0103 code.

    Error code: Assets\2D-Character-Controller-master\Caharcter2DController.cs(28,47): error CS0103: The name 'movement' does not exist in the current context


    Code (CSharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class Caharcter2DController : MonoBehaviour
    5. {
    6.     public float MovementSpeed = 1;
    7.  
    8.     //player must have a rigidbody2D and a box colider
    9.     public float moveSpeed = 5f;
    10.     // Start is called before the first frame update
    11.  
    12.     private void Start()
    13.     {
    14.    
    15.     }
    16.  
    17.     private void Update()
    18.     {
    19.  
    20.         {
    21.             Jump();
    22.             Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
    23.             transform.position += movement * Time.deltaTime * moveSpeed;
    24.         }
    25.  
    26.         {
    27.             var methodmovement = Input.GetAxis("Horizontal");
    28.             transform.position += new Vector3(movement,0, 0) * Time.deltaTime * MovementSpeed;
    29.         }
    30.     }
    31.  
    32.     void Jump()
    33.     {
    34.         if (Input.GetButtonDown("Jump"))
    35.         {
    36.             gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
    37.         }
    38.     }
    39. }
    40.  
    41. [/ICODE]
     
    Last edited: Jan 24, 2021
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    12,114
  3. DiasErik

    DiasErik

    Joined:
    Jan 22, 2021
    Posts:
    2
    I edit my post, now it's correct. The first link is doesen't work.
     
unityunity