简体   繁体   中英

Why am I getting a CS1001 error in my code?

I am a complete novice at C# coding so this might be a dumb question, but I can't figure out why I keep getting this error from my Unity script. It says "identifier expected," but as far as I know I already have an identifier?

{

    public float moveSpeed = 5f;

    public Rigidbody2D rb;

    public string animator;
    public string movement;

    Vector2 (movement);
    
    // Update is called once per frame
    void Update()
    {
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");

        animator.SetFloat("Horizontal", movement.x);
        animator.SetFloat("vertical", movemnet.y);
        animator.SetFloat("Speed", movement.sqrMagnitude);
    }

    void FixedUpdate()
    {
        rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
    }

}

Why are there parenthesis around movement in Vector2 (movement);

Also this variable needs to be initialized with a value.

Try Vector2 movement = new Vector2(0,0);

Also a spelling error here animator.SetFloat("vertical", *movemnet*.y);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM