Rory Hill
Rory Hill

Reputation: 29

Unity "type or namespace definition, or end-of-file expected." How to fix?

C#. Editor version:2021.3.16f1 I wanted to make a script where "Capsule" follows "PlayerArmature". I used this tutorial: YouTube and used this tutorial for the navmesh: YouTube But my unity has an error, and the script is greyed out. Here is my script:

using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using UnityEngine;

public class FOllow : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        public gameObject Capsule;
    public gameObject PlayerArmature;
    public float speed;

    }

    // Update is called once per frame
    void Update()
    {
    Capsule.transform.position = Vector3.MoveTowards(Capsule.transform.position, PlayerArmature.transform.position, speed);
    }
}

I am not sure what to do. My game does not nessasarily need collisions with walls, just the ability to walk up stairs.

I wanted the script to make the Capsule follow the PlayerArmature, but it gave me an error. I don't know how to fix it.

Upvotes: 1

Views: 30

Answers (1)

MrDiamond
MrDiamond

Reputation: 1082

You are defining the class's variables inside your Start function. This is not valid C# syntax. Also, the GameObject type has a capital G.

using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using UnityEngine;

public class FOllow : MonoBehaviour
{
    public GameObject Capsule;
    public GameObject PlayerArmature;
    public float speed;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        Capsule.transform.position = Vector3.MoveTowards(Capsule.transform.position, PlayerArmature.transform.position, speed);
    }
}

Upvotes: 2

Related Questions