Wie kann ich das (“Top-level statements must precede namespace and type declarations”) fixen?

Das kommt, wenn ich spielen will:

Assets\PipeSpawner.cs(33,9): error CS8803: Top-level statements must precede namespace and type declarations.

Aber es geht nicht.

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

public class PipeSpawner : MonoBehaviour
{
  public GameObject pipe;
  public float spawnRate = 2;
  public float timer = 0;

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

  // Update is called once per frame
  void Update()
  {
    if (timer < spawnRate)
    {
      timer = timer + Time.deltaTime;
    }
    else
    {
      spawnPipe();
      timer = 0;
    }
  }

  void spawnPipe();
}
{
  float lowestPoint = transform.position.Y - heigthOffset;
  float highestPoint = transform.position.y + heigthOffset;
  Instantiate(pipe, new Vector3 (transform.position.x, Random.Range(lowestPoint,highestPoint), 0),transform.rotation);
}

Kann mir jemand sagen, was falsch ist?

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
1 Answer
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Suiram1
8 months ago

In the declaration of spawnPipe-Method method must not be a semicolon after the parenthese of the parameters, otherwise the declaration is terminated there and the method body is not recognized.

Since, in addition, a shaft clamp according to the method body of spawnPipe is the class PipeSpawner ended there and the remaining code is interpreted as a top-level statement which has to get its own file.

Which IDE/Editor do you use? Actually, this would have to be noticed right away because the code formatting doesn’t seem at all.