Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class player_good : MonoBehaviour
{
    public float speed ;
    public float JumpForce;
    Rigidbody2D rb;
    bool OnGround;
    private Animator anim;
    SpriteRenderer sprite;
    // Start is called before the first frame update
    void Start()
    {
        rb=GetComponent<Rigidbody2D>();
        OnGround=true;
        sprite = GetComponent<SpriteRenderer>();
        anim=GetComponent<Animator>();
    }
    // Update is called once per frame
    void Update()
    {
        float player =Input.GetAxis("Horizontal");
        transform.position += new Vector3(player*speed,0,0);
        if (Input.GetKeyDown(KeyCode.Space)&&OnGround)
        {
             rb.AddForce(new Vector2(0,JumpForce));
             anim.SetTrigger("jump");
        }
        //flipping
        if (player>0)
        {
            sprite.flipX=false;
        }
        else if (player<0)
        {
            sprite.flipX=true;
        }
        if(player!=0)
        {
           anim.SetBool("is wolking",true);
        }
        else
        {
           anim.SetBool("is wolking",false);
        }
    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
       if (collision.gameObject.tag=="Ground")
       {
         OnGround=true;
       }
       else (collision.gameObject.Comparetag=="end")
       {
         SceneManagement.loadScene("Sample Scene");
       }
    }
    private void OnCollisionExit2D(Collision2D collision)
    {
       if (collision.gameObject.tag=="Ground")
       {
          OnGround=false;
       }
    }
}


What I have tried:

I got this error :Assets\player_good.cs(56,53): error CS1002:
Posted
Updated 25-Feb-23 4:25am
v2
Comments
Richard MacCutchan 25-Feb-23 3:59am    
Where is the line that causes the error, and what is the complete message?

To add to what Richard has - rightly - said ... You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!

And spending a little time learning to understand syntax error messages will save you a huge amount of time in future: you waited over half an hour for Richard to reply, then your email system probably added another 10 minutes or so, plus the time it took you to type up the question once you had found this site and created an account. Chances are that you could have saved a significant chunk of that time if you knew how to read them!

I'm not saying we don't want to help you fix them - sometimes I can't see my own errors because I read what I meant to write - but fixing syntax errors is part of the job, and if you can't do it for yourself people are going to look at you as a bit weird should you get a job in the industry!
 
Share this answer
 
Well a quick count down to line 56 reveals:
C#
else (collision.gameObject.Comparetag=="end")

Which is obviously incorrect, as the part after the else is a conditional expression. It should be:
C#
else if (collision.gameObject.Comparetag=="end") // requires the 'if' to make it correct.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900