- Home /
Question by
pollomagicoyt · May 02, 2020 at 12:48 PM ·
c#errorerror messagenewbie
Errors CS1513 and CS1022 - Need help.
I'm just getting started with Unity and I don't know why I'm getting these errors:
Assets\PlayerMovementScript.cs(15,19): error CS1513: } expected Assets\PlayerMovementScript.cs(48,1): error CS1022: Type or namespace definition, or end-of-file expected
I've double-checked all the curly brackets and it doesn't seem wrong to me. Any clue of what could be happening here? I'm sorry if it's a dumb question, but I can't find what the problem is. Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovementScript : MonoBehaviour {
public KeyCode upKey = KeyCode.W;
public KeyCode downKey = KeyCode.S;
public KeyCode rightKey = KeyCode.D;
public KeyCode leftKey = KeyCode.A;
public float speed = 4.0f;
public Vector3 pos = player.transform.position;
void Start() {
public GameObject player = GameObject.Find("Player");
}
void Update() {
if (Input.GetKeyDown(upKey))
{
pos.y += speed * Time.deltaTime;
}
if (Input.GetKeyDown(downKey))
{
pos.y -= speed * Time.deltaTime;
}
if (Input.GetKeyDown(rightKey))
{
pos.x += speed * Time.deltaTime;
}
if (Input.GetKeyDown(leftKey))
{
pos.x -= speed * Time.deltaTime;
}
player.transform.position = pos;
}
}
Thanks in advance!
Comment
Best Answer
Answer by gjf · May 02, 2020 at 12:47 PM
You can't define player
in Start()
in the way that it's written. Change to the following:
public GameObject player;
public Vector3 pos;
void Start()
{
player = GameObject.Find("Player");
pos = player.transform.position;
}
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Help please guys thank you so much! 1 Answer
Help with basic AI script 1 Answer