I need help again LOL

im using unity 2021.1.5
i was making a game for android and the script got an error that i realy realy can’t figure out pls help
btw the script is for checking if internet is on or off
here is the script:
using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.Networking;

public class CheckInternet : MonoBehaviour

{

public GameObject InternetUI;

public object Else { get; set; }

// Start is called before the first frame update

void Start()

{

{

   

}    

}

private static void NewMethod()

{

   

}



// Update is called once per frame

void Update()

{

    if (Application.internetReachability==NetworkReachability.ReachableViaLocalAreaNetwork) NewMethod();

    Debug.Log("Available");

   InternetUI.SetActive(false);

   Else if (Application.internetReachability==NetworkReachability.NotReachable) NewMethod();

   Debug.Log("Not Available");

   InternetUI.SetActive(true);

          

}

}

What is the error you’re getting?

Your NewMethod() isn’t doing anything

Your if else statement is all wrong, it has no scope, and your else is capitalized. Not having a scope is something you can only do if you want only one thing to happen during the if statement, but you’re also trying to use Debug.Log and InternetUI.SetActive()
basically, your update function just keeps printing both available and not available and setting InternetUI off and then on again every game tick (assuming it even runs)
You need to add scope brackets like so:

if (Application.internetReachability==NetworkReachability.ReachableViaLocalAreaNetwork) 
	{
	NewMethod();
    Debug.Log("Available");
	InternetUI.SetActive(false);
	}
else if (Application.internetReachability==NetworkReachability.NotReachable) 
	{
	NewMethod();
	Debug.Log("Not Available");
	InternetUI.SetActive(true);
	}

Also, you have a random set of extra scope brackets in Start(), that shouldn’t do anything but I’d remove it anyway just in case.

Edit:
Also also, I just realised that you have a public object Else { get; set; }, not really sure what your plan for this is since it doesn’t seem to be in use at the moment but else is a reserved word in most (in not all) programming languages. While using capitalised Else is technically legal as a variable name, you should probably avoid doing that.

ok lol im very noob :/. by the way thx for ur help again. i didn’t reply as soon bc i was busy this days.
praticaly i did put Else and not else bc. if i put just else somehow i get like other 3 errors btw here is the error: says this: error CS1002: ; expected but the problem is WHERE, i did put ; everywhere i need atleast i think. the public object Else {get; get;} it was to fix ANOTHER error visual studio gaved me this solution. btw thx im now fixing my script thx.

omg it worked. and again like last time ist a confirm that i don’t pay much attention :/. thx so much im now studying the script so i can se my errors thx so much, bye.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms