I was making a custom column and sfx slider for my game that saves preferences and I got the error code CS0029:
Assets/Scripts/Menu/Music.cs(59,36): error CS0029: Cannot implicitly convert type ‘float’ to ‘UnityEngine.AudioSource’
the code is
using UnityEngine;
using UnityEngine.UI;
public class Music : MonoBehaviour
{
private static readonly string FirstPlay = “FirstPlay”;
private static readonly string BackgroundPref = “BackgroundPref”;
private static readonly string SoundEffectsPref = “SoundEffectsPref”;
private int firstPlayInt;
public Slider backgroundSlider, soundEffectsSlider;
private float backgroundFloat, soundEffectsFloat;
public AudioSource backgroundAudio;
public AudioSource[ ] soundEffectsAudio;
public void UpdateSound()
{
backgroundAudio.volume = backgroundSlider.value;
for(int i = 0; i < soundEffectsAudio.Length; i++)
{
soundEffectsAudio = soundEffectsSlider.value; } } } if anybody could help I would really appreciate it sorry for any trouble I am new to programming
Hello. I tried to make a score and high score for my game by using Player Prefs but got the error CS0029 in the console.
Here is my code :
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public Transform player;
public Text scoreText;
public Text highscoreText;
void Start()
{
highscoreText.text = PlayerPrefs.GetInt("HighScore", 0).ToString();
}
void Update()
{
int number = player.position.z.ToString("0");
scoreText.text = number.ToString();
if (number > PlayerPrefs.GetInt("HighScore", 0))
{
PlayerPrefs.SetInt("HighScore", number);
highscoreText.text = number.ToString();
}
}
}
Here is also the error message:
Assets\Scripts\Score.cs(17,22): error CS0029: Cannot implicitly convert type ‘string’ to ‘int’