mercredi 18 août 2021

(64,3): error CS1022: Type or namespace definition, or end-of-file expected

Im noob to c# and i was coding a move+animations script for a unity game and got this error: (64,3): error CS1022: Type or namespace definition, or end-of-file expected what is this wrong with the code its a mix of different codes i wrote off of youtube and im trying to make a zelda like game the script (including the error line) was working perfectly until i added the enum and the IEnumerator? code:

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

public enum PlayerState
{
    walk,
    attack,
    interact
}

public class PlayerMovementBase
{
}

[DebuggerDisplay("{" + nameof(GetDebuggerDisplay) + "(),nq}")]
public class PlayerMovement : MonoBehaviour
{
    public PlayerState currentState;
    public Animator anim;
    public float moveSpeed;
    public float x, y;

    private bool isWalking;
    private Vector3 moveDir;
    private Rigidbody2D rb;
    private bool isAttacking;
    
    private void Start()
    {
        currentState = PlayerState.walk;
        anim = GetComponent<Animator>();
        rb = GetComponent<Rigidbody2D>();
    }

    private void Update()
    {
        x = Input.GetAxisRaw("Horizontal");
        y = Input.GetAxisRaw("Vertical");

        if(Input.GetButtonDown("attack") && currentState != PlayerState.attack)
        {
            StartCoroutine(AttackCo());
        }
    }
    
    private IEnumerator AttackCo()
    {
        animator.SetBool("IsAttacking", true);
        currentState = PlayerState.attack;
        yield return null;
        animator.SetBool("IsAttacking", false);
        yield return new WaitForSeconds(.3f);
        currentState = PlayerState.walk;
    }
           
private string GetDebuggerDisplay()
    {
        return ToString();
    }
}

  if (x != 0 || y != 0)
  {
    anim.SetFloat("X", x);
    anim.SetFloat("Y", y);
    if (!isWalking)
    {
        anim.SetBool("IsMoving", isWalking);
        isWalking = true;
    }
  }else
    {
            if (isWalking)
            {
                isWalking = false;
                anim.SetBool("IsMoving", isWalking);
                StopMoving();
            }
        }
        moveDir = new Vector3(x, y).normalized;
    }

    

    private void FixedUpdate()
    {
        rb.velocity = moveDir * moveSpeed * Time.deltaTime;
    }

    private void StopMoving()
    {
        rb.velocity = Vector3.zero;
    }
}

Aucun commentaire:

Enregistrer un commentaire