Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Can someone help me with my top down movement script

A topic by DrunkenLeaf created May 02, 2021 Views: 176 Replies: 2
Viewing posts 1 to 3
Submitted

I cant find where to fix this error, assets.playermovement.cs (11,36): error CS1002: ; expected.

here is the code 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class PlayerMovement : MonoBehaviour

{

    public float moveSpeed;

    public Rigidbody2D rb;

    

    private Vector2 moveDirection()

    // Update is called once per frame

    void Update()

    {

        ProcessInputs();

    }

    void fixedUpdate()

    {

        // physics Calculations

        Move();

    }

    void ProcessInputs()

    {

        float moveX = Input.GetAxisRaw("Horizontal");

        float moveY = Input.GetAxisRaw("Vertical");

        moveDirection = new Vector2(moveX, moveY).normalized;

    }

    void Move()

    {

        rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);

    }

}

Submitted

idk lotsa unity, but maybe add a semicolon after     private Vector2 moveDirection() ?

Submitted

Yes, you probably wanted to write:  private Vector2 moveDirection;

You are declaring a variable, not a function.