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. Dismiss Notice

how to fix my error

Discussion in 'Scripting' started by pinkpenguindev, Sep 28, 2020.

  1. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    Assets\movement.cs(8,27): error CS1003: Syntax error, ',' expected
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class movement : MonoBehaviour
    6. {
    7.  
    8.    public float movespeed 10f;
    9.  
    10.  
    11.    public Rigidbody2D rb;
    12.  
    13.  
    14.     // Start is called before the first frame update
    15.     void Start()
    16.     {
    17.         rb = getComponent<Rigidbody2D>();
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.        
    24.     }
    25. }
    26.  
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    You forgot the '=':
    Code (CSharp):
    1. public float movespeed = 10f;
     
  3. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
  4. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    well i did it and now
    Assets\movement.cs(17,14): error CS0103: The name 'getComponent' does not exist in the current context
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class movement : MonoBehaviour
    6. {
    7.  
    8. public float movespeed = 10f;
    9.  
    10.  
    11.    public Rigidbody2D rb;
    12.  
    13.  
    14.     // Start is called before the first frame update
    15.     void Start()
    16.     {
    17.         rb = getComponent<Rigidbody2D>();
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.        
    24.     }
    25. }
    26.  
     
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    getComponent
    should be
    GetComponent
     
  6. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
  7. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    Assets\movement.cs(25,63): error CS1003: Syntax error, ',' expected new code
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class movement : MonoBehaviour
    6. {
    7.  
    8. public float movespeed = 10f;
    9.  
    10.  
    11.    public Rigidbody2D rb;
    12.  
    13.  
    14.     // Start is called before the first frame update
    15.     void Start()
    16.     {
    17.         rb =GetComponent<Rigidbody2D>();
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.      //"a" = "-1"
    24.      //"d" = "1"
    25.    Vector3 movement = new Vector3(input.GetAxis("horizontal") 0f 0f );
    26.    transform.position += movement * Time.deltaTime * movespeed;
    27.     }
    28. }
    29.  
     
  8. Sphinks

    Sphinks

    Joined:
    Apr 6, 2019
    Posts:
    267
    you forgot the , between 0f and 0f in line 25.

    it has to be
    Code (CSharp):
    1. Vector3 movement = new Vector3(input.GetAxis("horizontal") 0f, 0f );
     
  9. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    its still there
     
  10. Sphinks

    Sphinks

    Joined:
    Apr 6, 2019
    Posts:
    267
    ahh yeah sry, missed another , before the first 0f

    Code (CSharp):
    1. Vector3 movement = new Vector3(input.GetAxis("horizontal"), 0f, 0f );
    if you have different parameters for a method you have to "split" them each time with ,
     
  11. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    Assets\movement.cs(25,35): error CS0103: The name 'input' does not exist in the current context
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class movement : MonoBehaviour
    6. {
    7.  
    8. public float movespeed = 10f;
    9.  
    10.  
    11.    public Rigidbody2D rb;
    12.  
    13.  
    14.     // Start is called before the first frame update
    15.     void Start()
    16.     {
    17.         rb =GetComponent<Rigidbody2D>();
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.      //"a" = "-1"
    24.      //"d" = "1"
    25.    Vector3 movement = new Vector3(input.GetAxis("horizontal"), 0f, 0f );
    26.    transform.position += movement * Time.deltaTime * movespeed;
    27.     }
    28. }
    29.  
     
  12. Sphinks

    Sphinks

    Joined:
    Apr 6, 2019
    Posts:
    267
    Input with a big I.

    If you use Visual Studio you should have auto-complition, that should actually solve problems like that.
     
  13. pinkpenguindev

    pinkpenguindev

    Joined:
    Aug 13, 2020
    Posts:
    43
    i dont i download it from not unity