Help me Assets/Player.cs(55,2): error CS1513: } expected

Vlad Zai 1 Reputation point
2022-04-02T17:23:51.767+00:00

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
public float checkRadius;
public LayerMask whatIsGround;
public bool canMove;

public float speed;
public float minX, maxX;

public Vector2 targetPos;
private Animator anim;

private void Start()
{
    anim = GetComponent<Animator>();
}


public void Update()
{
    canMove = Physics2D.OverlapCircle(transform.position, checkRadius, whatIsGround);

    if (Input.GetKeyDown(KeyCode.A) && transform.position.x > minX && canMove)
    {
        targetPos = new Vector2(minX, transform.position.y);
        StartCoroutine(AfterMove());
    }
    else if (Input.GetKeyDown(KeyCode.D) && transform.position.y);
    {
        targetPos = new Vector2(maxX, transform.position.y);
        StartCoroutine(AfterMove());
    }

    transform.position = Vector2.MoveTowards(transform.position, targetPos, speed * Time.deltaTime);


    }

    public IEnumerator AfterMove()
    {
        new WaitForSeconds(.13f);
        new WaitUntul(() => transform.position.x == maxX || transform.position.x == minX);
        if (transform.position.x == maxX)
        {
            anim.SetTrigger("left");
        }
        else if (transform.position.x == minX)
        {
            anim.SetTrigger("right");
        }

}

Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,401 Reputation points
    2022-04-02T18:16:52.267+00:00

    Look at how the web site formatted your question. Some of it is in text and a large portion has line numbers. You need to use the Code Sample tool when posting code. That's the 101010 icon.

    Assuming that you posted everything, it looks like you just need an ending "}".

    Check the starting and ending brackets of each function. Note that the cursor is on the bracket on line 15, and it's matching ending bracket on line 17 has a gray background. You can also click on the minus signs on lines 12 and 14 to collapse that portion of code. That should help you identify what code is part of what statement.

    189437-capture7.png

    Proper indentation also helps. Everything in a "{}" block should be indented one tab. That should help you match up the start and end of the code block.

    using System.Collections;  
    using System.Collections.Generic;  
    using UnityEngine;  
      
    public class Player : MonoBehaviour  
    {  
    	public float checkRadius;  
    	public LayerMask whatIsGround;  
    	public bool canMove;  
      
    	public float speed;  
    	public float minX, maxX;  
          
    	public Vector2 targetPos;  
    	private Animator anim;  
    		  
    	private void Start()  
    	{  
    		 anim = GetComponent<Animator>();  
    	}	  
    		  
    	public void Update()  
    	{  
    		canMove = Physics2D.OverlapCircle(transform.position, checkRadius, whatIsGround);  
    			  
    		 if (Input.GetKeyDown(KeyCode.A) && transform.position.x > minX && canMove)  
    		 {  
    			 targetPos = new Vector2(minX, transform.position.y);  
    			 StartCoroutine(AfterMove());  
    		 }  
    		 else if (Input.GetKeyDown(KeyCode.D) && transform.position.y);  
    		 {  
    			 targetPos = new Vector2(maxX, transform.position.y);  
    			 StartCoroutine(AfterMove());  
    		 }  
    		 transform.position = Vector2.MoveTowards(transform.position, targetPos, speed * Time.deltaTime);				  
    	}  
    			  
    	public IEnumerator AfterMove()  
    	{  
    		 new WaitForSeconds(.13f);  
    		 new WaitUntul(() => transform.position.x == maxX || transform.position.x == minX);  
    		 if (transform.position.x == maxX)  
    		 {  
    			 anim.SetTrigger("left");  
    		 }  
    		 else if (transform.position.x == minX)  
    		 {  
    			 anim.SetTrigger("right");  
    		 }  
    	}  
    }  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.