I keep getting the 'Unexpected Symbol' error but cant find whats wrong with code
I'm trying to make it to where the enemy character slowly follows the player. i found this code in a form on here because i'm not the best with scripts. I've looked over the code a thousand times and can't find why i am given the error. Here's the script
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class followPlayer : MonoBehaviour {
void Start () {
var Player; Transform;
var MoveSpeed = 4;
var MaxDist = 10;
var MinDist = 5;
function Start ()
{
}
function Update ()
{
transform.LookAt(Player);
if(Vector3.Distance(transform.position,Player.position) >= MinDist){
transform.position += transform.forward*MoveSpeed*Time.deltaTime;
}
}
// Update is called once per frame
void Update () {
}
}
Answer by Backside2357 · May 08, 2017 at 09:44 PM
First of all, I'm not sure if the following line can work (I didn't use the var keyword yet):
var Player; Transform;
The semicolon after Player should be a comma (I think). But as far as I see you don't need the Transform variable at all. So you can delete it.
Second, I'm not sure what you try to accomplish with your
function Start() {}
function Update() {}
blocks. I have never seen a function
keyword in C# and I'm pretty sure it doesn't exist. The void Start() {}
block already is your Start function and void Update() {}
is your Update function. Move your var definitions outside any function (that means directly after public class followPlayer : MonoBehaviour {
and before void Start() {}
and put the rest of the code in the real Update function.
Your answer
![](https://koobas.hobune.stream/wayback/20220612121554im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can't add script to anything. 1 Answer
How to teleport a car? 1 Answer
Storing levels data 1 Answer
Trying to simulate SNES party snake, non-grid. 0 Answers
[HELP] How to lock input key? 1 Answer