error CS1519: Invalid token 'bool' in class, struct, or interface member declaration

Hi

I’m having a problem with Unity 2020.1.4f1. The console is send this error: Assets\scrits\volumenMusica.cs(9,5): error CS1519: Invalid token ‘bool’ in class, struct, or interface member declaration.

This is my code:

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

public class volumenMusica : MonoBehaviour
{
    public underwater

    bool underwater = true;
    bool underwater = false;
    public AudioSource musicaUp;
    public AudioSource musicaDown;

    float velVolumen = 1f;

    // Start is called before the first frame update
    void Start()
    {
        musicaUp.volume = 1;
        musicaDown.volume = 0;
    }

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

        if (underwater)
        {
            if (musicaUp.volume > 0) { musicaUp.volume -= Time.deltaTime * velVolumen; }
            if (musicaDown.volume > 1) { musicaDown.volume += Time.deltaTime * velVolumen; }
        }
        else
        {
            if (musicaUp.volume < 1) { musicaUp.volume += Time.deltaTime * velVolumen; }
            if (musicaDown.volume < 0) { musicaDown.volume -= Time.deltaTime * velVolumen; }
        }
    }
}

You have “public underwater” - by itself this isn’t valid. There’s no type and no semicolon. Underneath that you have 2 bools named underwater. Try replacing those 3 lines with just “public bool underwater;”

2 Likes

If I do that the console send this: Assets\scrits\volumenMusica.cs(9,17): error CS0102: The type ‘volumenMusica’ already contains a definition for ‘underwater’ and Assets\scrits\volumenMusica.cs(10,17): error CS0102: The type ‘volumenMusica’ already contains a definition for ‘underwater’

That’s what they mentioned above.
You have a duplicate variable declaration:

bool underwater = true;
bool underwater = false;

Just remove one of these declarations.

I did but now the console says this: Assets\scrits\volumenMusica.cs(9,10): error CS0102: The type ‘volumenMusica’ already contains a definition for ‘underwater’

Then you still have multiple declarations for the same variable name. Remove them until you only have one.

Then what do I do?

Ideally you go and learn the basics of the programming language you’re trying to use.

https://csharp.net-tutorials.com/getting-started/introduction/

1 Like

Ok I’m trying

1 Like