Compiler can not get past declaring this method?

I’m trying to compile this code that is literally from the Unity API just to see it in action, but whenever I try to compile it I get an error that says “} expected” directly after the open bracket on public void openDoors(){

Does anyone know what is wrong here that is causing that?

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

public class ElevatorDoors : MonoBehaviour {

public void openDoors(){
public Transform target;
public float smoothTime = 0.3f;
private Vector3 velocity = Vector3.zero;
Vector3 targetPosition = target.TransformPoint(new Vector3(0,0, 5));
transform.position += Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);

}

You cannot use public/private within a function body, only within the class member variables themselves.

You need another “}” to terminate the class. You only have one to end the “openDoors” method.

1 Like

This is how it should look;

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

public class ElevatorDoors : MonoBehaviour
{
    public Transform target;
    public float smoothTime = 0.3f;
    private Vector3 velocity = Vector3.zero;
   
    public void openDoors()
    {
        Vector3 targetPosition = target.TransformPoint(new Vector3(0,0, 5));
        transform.position += Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
    }
}