using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 5f;
public Rigidbody 2D rb
public Weapon weapon;
Vector2 moveDirection;
Vector2 mousePosition;
// Update is called once per frame
void Update()
{
float moveX = Input.GetAxisRaw("Horizontal");
float moveY = Input.GetAxisRaw("Vertical");
if(Input.GetMouseButtonDown(0))
{
weapon.Fire();
}
moveDirection = new Vector2(moveX, moveY).normalized;
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
private void FixedUpdate()
{
rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);
Vector2 aimDirection = mousePosition - rb.position;
float aimAngle = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg - 90f;
rb.rotation = aimAngle;
}
}
I'm working on a prototype for my top down shooter game, the code is based on the 5-minute top down shooter by BMo, this is my code for the character controller but I am getting the following errors. Anyone have advice to fix it? (Note: I am working on a Mac with Visual Studio Code)
(8,22) Invalid token 2D in class, record, struct, or interface member declaration
(8, 27) Invalid token ; in class, record, struct, or interface member declaration
I am relatively new to coding so any help is greatly appreciated 🙂