[HELP] Is the code right?

I am not sure if the code below is right, because I got an error message on Console:

Assets/Scripts/DiceManager.cs(15,35):error cs0029: Cannot implicitly convert type ‘void’ to ‘UnityEngine.UI.Button’

The code of DiceManager is as follows:

"using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DiceManager : MonoBehaviour {

public Button startOver;
public Button continueGame;

// Use this for initialization
void Start () {
    startOver.gameObject.SetActive(false);
    continueGame = gameObject.SetActive(false);
}

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

}
"
Your input would be much appreciated.

Thank you.

Hi there,

the line continueGame = gameObject.SetActive(false); is the problem here, it should be like the previous line:

startOver.gameObject.SetActive(false);
continueGame.gameObject.SetActive(false);

By putting an equal sign there, you’re asking the compiler to assign the value of gameObject.SetActive(false); to the variable continueGame, but since SetActive() returns void and continueGame is a Button, the compiler throws this error.

Privacy & Terms