Why do I have errors on all of my private declarations and on my void update?

using UnityEngine;
using System.Collections;

public class NetworkController : MonoBehaviour {

	// Use this for initialization
	void Start () {
		private const string typeName = "TestGame";
		private const string gameName = "Room1";
		
		private void StartServer()
		{
			Network.InitializeServer(4, 25000, !Network.HavePublicAddress());
			MasterServer.RegisterHost(typeName, gameName);
		}
	}
	
	
	// Update is called once per frame
	void Update () {
	
	}
}

1 Answer

1

You should really learn to code first, before you are messing with Unity. Your code gives you errors because:

  1. You declared a methode in a methode
  2. You declared const vars in a methode
  3. You give vars in a methode privatie settings

Here is your code corrected:

using UnityEngine;
using System.Collections;

public class NetworkController : MonoBehaviour
{

    private const string typeName = "TestGame";
    private const string gameName = "Room1";

    // Use this for initialization
    void Start()
    {
        StartServer();
    }

    private void StartServer()
    {
        Network.InitializeServer(4, 25000, !Network.HavePublicAddress());
        MasterServer.RegisterHost(typeName, gameName);
    }


    // Update is called once per frame
    void Update()
    {

    }
}

You can have it :)

I don't really recommend it, as a simple loop would be more readable and more efficient, but this fits your one line requirement using System.Linq LightSources.ForEach(light => light.enabled = false); still just a loop on the backend