Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
lucian112

error CS1525: Unexpected symbol `else'

Question

What's wrong?

 

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

namespace Networking
{
    public class ComponentsToDisable : NetworkBehaviour
    {
        public List<Behaviour> Components = new List<Behaviour>();

        private void Start()
        {
            if (!isLocalPlayer)
            {
                for (int i = 0; i < Components.Count; i++)
                {
                    Components.enabled = false;
                }
            {
             else
            }
                Camera.main.gameObject.SetActive(false);
            }
        }
    }
}

 

 

Share this post


Link to post
Share on other sites

8 answers to this question

Recommended Posts


  • 0
Please login or register to see this quote.

Please login or register to see this link.  Evrything like in video ,i don;t understand

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

When I read your answer, I said to myself you are trolling us :)

Many of these brackets could be ignored in this script. I have never understand why some want to put brackets when there is only one command line after a condition.

Also I noticed that you forgot to add index in your loop. How could you disable some components?

Take a look at this script which works as expected ++

 

Please login or register to see this code.
  • Like 1

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

It is usually personal preference, but it is recommended to do it. Because if you don't put brackets and then you add something new in the if state, then there will be bugs if you forget to add those brackets. Also for me it is easier to read when there's brackets, I can just skim through the code and easily see when the if and ifelse statement ends :-)

  • Thanks 1

Share this post


Link to post
Share on other sites
  • 0

Personal preference. For one line it's just useless...

I guess that a debate about it could be even more useless :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...