Help! I've been trying to fix this for too long.

Szymon Pecherski 1 Reputation point
2022-11-01T08:00:57.807+00:00

I'm getting the following error codes and have been struggling to fix them for quite some time now;
Assets\missionProgress.cs(9,10): error CS1513: } expected
Assets\missionProgress.cs(17,5): error CS8803: Top-level statements must precede namespace and type declarations.
Assets\missionProgress.cs(32,1): error CS1022: Type or namespace definition, or end-of-file expected

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

public class missionProgress : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
public Transform missionCheck;
public float missionDistance = 1f;
public LayerMask missionMask;
public int missionNext = 0;
}

// Update is called once per frame  
void Update()  
    {  
    missionStep = Physics.CheckSphere(missionCheck.position, missionDistance, missionMask);  

    if (missionStep == true)  
        {  
        missionNext =+ 1;  
        }  

    switch(missionNext)  
        {  
        case 1:  
           Destroy(m1, 1);  
        }  
    }  

}

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,307 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,931 Reputation points
    2022-11-01T15:38:58.663+00:00

    so little code, so many errors,

    1) you can not define properties inside a function:

    void Start()
    {
    public Transform missionCheck;
    public float missionDistance = 1f;
    public LayerMask missionMask;
    public int missionNext = 0;
    }

    2) variables must be defined before used:

    missionStep =   
    

    3) object property used without allocating object (missionCheck.position)

    missionStep = Physics.CheckSphere(missionCheck.position, missionDistance, missionMask);

    4) case statements in a switch must have a break

    0 comments No comments