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;”
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’
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’