Random bracket error bug?

I was wondering if there is a known bug with Mono and how it detects brackets

I keep getting this error.
c:\Users\Lapgar\Documents\New Unity Project\Assets\HomeMadeAssets\scripts\DoorManagerA.cs(4,4): Error CS1513: } expected (CS1513) (Assembly-CSharp)

Here is the code it claims is wrong.

using UnityEngine;
using System.Collections;

public class DoorManagerA : MonoBehaviour {

    public Door door1;
    public Door door2;
    public bool hadLoadedLevelA;
    public bool hadLoadedLevelB;
    public GameObject spawnObject;
    //public GameObject OldObject;


    void OnTriggerEnter(){

        //int whichDoor = 0;
        if (door1!=null)
        {
            door1.OpenDoor();
            //Debug.Log("\n" + this.transform.position.x + " " + this.transform.position.y + " " + this.transform.position.z + " ");
            //whichDoor = 1;


        }
 
        if (door2!=null)
        {
            door2.OpenDoor();
            //whichDoor = 2;

        }

        if(!hadLoadedLevelA)
        {
            CreatePrefab(1);
            hadLoadedLevelA = true;
        }

        if(!hadLoadedLevelB)
        {
            CreatePrefab(2);
            hadLoadedLevelB = true;
        }


    }

    void CreatePrefab(int loadType)
    {
        //LoadType 1 = hadLevelLoadedLevel A which means door 1 which means longdoor1 opened
        //LoadType 2 = hadLevelLoadedLevel B which means door 2 which means longdoor1 opened
        Vector3 nextRoom = this.transform.position;
        if(loadType == 2)
        {
            //Where it will appear next
            nextRoom.y = nextRoom.y;
            nextRoom.z = nextRoom.z + 5.59369f;
            nextRoom.x = nextRoom.x - 12f;
        }
        //nextRoom.x = nextRoom.x + 1.3f;
        //nextRoom.z = nextRoom.z + -5.59369f;
        //nextRoom.x = nextRoom.x - 13.25f;
        //nextRoom.x = nextRoom.x - 13.25f; space of the rooms not the door manager object, which is what this.transform.position is
        //The original transformer, not the current one. Each means no clones of clones of clones


        //Debug.Log ("\n" );
        GameObject clone = Instantiate(spawnObject.transform, nextRoom, spawnObject.transform.rotation) as GameObject;
    }
}

and here is what I did to “fix it”.


using UnityEngine;
using System.Collections;

public class DoorManagerA : MonoBehaviour {

    public Door door1;
    public Door door2;
    public bool hadLoadedLevelA;
    public bool hadLoadedLevelB;
    public GameObject spawnObject;
    //public GameObject OldObject;


    void OnTriggerEnter(){

        //int whichDoor = 0;
        if (door1!=null)
        {
            door1.OpenDoor();
            //Debug.Log("\n" + this.transform.position.x + " " + this.transform.position.y + " " + this.transform.position.z + " ");
            //whichDoor = 1;


        }
 
        if (door2!=null)
        {
            door2.OpenDoor();
            //whichDoor = 2;

        }

        if(!hadLoadedLevelA)
        {
            CreatePrefab(1);
            hadLoadedLevelA = true;
        }

        if(!hadLoadedLevelB)
        {
            CreatePrefab(2);
            hadLoadedLevelB = true;
        }


    }

    void CreatePrefab(int loadType)    {
        //LoadType 1 = hadLevelLoadedLevel A which means door 1 which means longdoor1 opened
        //LoadType 2 = hadLevelLoadedLevel B which means door 2 which means longdoor1 opened
        Vector3 nextRoom = this.transform.position;

            //Where it will appear next
            nextRoom.y = nextRoom.y;
            nextRoom.z = nextRoom.z + 5.59369f;
            nextRoom.x = nextRoom.x - 12f;
        GameObject clone = Instantiate(spawnObject.transform, nextRoom, spawnObject.transform.rotation) as GameObject;}}

I did nothing but move the last two brackets up to the last line of code. Yet Unity was fine with this when I built it, but not fine with it before.

From what I can tell there is nothing wrong the first time, but mono just goes crazy unless I do the second version.

I should also note that I do not recall getting this error until I updated to the latest version of unity, 4.6.1f1.

Your first script looks ok and generates no error for me. Perhaps for some reason the script did not save changes and the error relates to a previously compiled version?

I found that going into Mono “Project > Assembly-CSharp Options > Build > General”
and changing the Target Framework from Mono / .net 3.5, to.net Framework 4.5.2 fixed the problem as well.

Why was Mono / .net 3.5 selected as default? Doing this also doesn’t seem to change the Target Framework to the newly selected framework for all scripts, just the one you are working on. I see this being a problem later on, but seems to be working just fine now.