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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

error CS1026: ) expected

Discussion in 'Scripting' started by experttrolador, Feb 14, 2021.

Thread Status:
Not open for further replies.
  1. experttrolador

    experttrolador

    Joined:
    Feb 3, 2021
    Posts:
    8
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class jump : MonoBehaviour
    6. {
    7.     private PlayerBase playerbase;
    8.     private Rigidbody2D rb2d;
    9.     private BoxCollider2D boxCollider2d;
    10.  
    11.    
    12.     private void Awake()
    13.     {
    14.         playerbase = gameObject.GetComponent<PlayerBase>();
    15.         rb2d = transform.GetComponent<Rigidbody2D>();
    16.     }
    17.  
    18.    
    19.     private void Update()
    20.     {
    21.         if (Isgrounded() && Input.GetKeyDown(KeyCode.Space))
    22.         {
    23.             float JumpVelocity = 40f;
    24.             rb2d.velocity = Vector2.up * JumpVelocity;
    25.         }
    26.  
    27.     }
    28.     private bool Isgrounded ()
    29.     {
    30.         RaycastHit2d raycastHit2d = Physics2D.BoxCast(boxCollider2d.bounds.center, boxCollider2d.bounds.size, 0f, Vector2.down * .1); if (
    31.         !Debug.Log(raycastHit2d.collider);
    32.         return raycastHit2d.collider != null;
    33.     }
    34. }
    35.  
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,245
    Your error message includes this
    (31,42)
    . That is telling you your error is nearby line 31, column 42 in the file.

    Look at the end of line 30. There's a rogue
    if (


    Also at the beginning of line 31. There's a rogue
    !


    Remove those.
     
    bilalaynaou28 and Bunny83 like this.
  3. experttrolador

    experttrolador

    Joined:
    Feb 3, 2021
    Posts:
    8
    I try that but now i have 2 errors:
    (31,41): error CS1026: ) expected
    error CS1003: Syntax error, '(' expected
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,245
    Show your code after making the changes
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    29,760
    Bunny83, experttrolador and ZO5KmUG6R like this.
  6. experttrolador

    experttrolador

    Joined:
    Feb 3, 2021
    Posts:
    8
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class jump : MonoBehaviour
    {
    private PlayerBase playerbase;
    private Rigidbody2D rb2d;
    private BoxCollider2D boxCollider2d;


    private void Awake()
    {
    playerbase = gameObject.GetComponent<PlayerBase>();
    rb2d = transform.GetComponent<Rigidbody2D>();
    }


    private void Update()
    {
    if (Isgrounded() && Input.GetKeyDown(KeyCode.Space))
    {
    float JumpVelocity = 40f;
    rb2d.velocity = Vector2.up * JumpVelocity;
    }

    }
    private bool Isgrounded ()
    {
    RaycastHit2d raycastHit2d = Physics2D.BoxCast(boxCollider2d.bounds.center, boxCollider2d.bounds.size, 0f, Vector2.down * .1); if
    Debug.Log(raycastHit2d.collider);
    return raycastHit2d.collider != null;
    }
    }
     
  7. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    You never removed the rogue "if" that PraetorBlue told you to.
     
    mopthrow and PraetorBlue like this.
  8. experttrolador

    experttrolador

    Joined:
    Feb 3, 2021
    Posts:
    8
    [QUOTE = "bobisgod234, publicación: 6838214, miembro: 1207668"] Nunca eliminó el pícaro "si" que PraetorBlue le dijo que lo hiciera. [/ QUOTE]
    (30,9): error CS0246: No se pudo encontrar el tipo o nombre del espacio de nombres 'RaycastHit2d' (¿le falta una directiva using o una referencia de ensamblado?)
    A new error :c i am sou dump in this of coding but here is the code:
    usando System.Collections;
    utilizando System.Collections.Generic;
    usando UnityEngine;

    salto de clase pública: MonoBehaviour
    {
    base de jugadores privada de PlayerBase;
    private Rigidbody2D rb2d;
    privado BoxCollider2D boxCollider2d;


    vacío privado Awake ()
    {
    playerbase = gameObject.GetComponent <PlayerBase> ();
    rb2d = transform.GetComponent <Rigidbody2D> ();
    }


    Actualización de vacío privado ()
    {
    if (Está conectado a tierra () && Input.GetKeyDown (KeyCode.Space))
    {
    flotar JumpVelocity = 40f;
    rb2d.velocity = Vector2.up * JumpVelocity;
    }

    }
    bool privado Isgrounded ()
    {
    RaycastHit2d raycastHit2d = Physics2D.BoxCast (boxCollider2d.bounds.center, boxCollider2d.bounds.size, 0f, Vector2.down * 1);
    Debug.Log (raycastHit2d.collider);
    return raycastHit2d.collider! = null;
    }
    }
     
  9. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    It is "RaycastHit2D", not "RaycastHit2d". Note the capital D, it is important, as C# is a caps-sensitive language.

    If you are following a tutorial, make sure your code matches exactly. There is absolutely no room for mistakes when writing code.
     
  10. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,662
    Bunny83, Joe-Censored and Kurt-Dekker like this.
  11. experttrolador

    experttrolador

    Joined:
    Feb 3, 2021
    Posts:
    8
    [QUOTE = "zombiegorilla, publicación: 6838472, miembro: 105706"] Lea las reglas. Use etiquetas de código y ponga un poco de esfuerzo en su publicación, simplemente publicar un error y algo de código es una publicación de bajo esfuerzo. Publica detalles, lo que has intentado, lo que está fallando y, en general, más información. La próxima vez se eliminará tu publicación.

    https://forum.unity.com/threads/unity-community-code-of-conduct.743180/ [/ QUOTE]
    thanks, i dont know that.
     
  12. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    29,760
    Please do not necro-post for your own typing mistakes. Just go fix your typing mistakes.

    What parts of "How to read error messages" are you struggling with?

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/
     
Thread Status:
Not open for further replies.