Hi I'm new to Unity I have this error in unity but my code said no issues

Hi I have error in Unity but not no issues with my code

This is the error:
CS7036: There is no argument given that corresponds to the required formal parameter ‘scoreToAdd’ of ‘LogicScript.addScore(int)’

This is my Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class LogicScript : MonoBehaviour

{
public int playerScore;
public Text scoreText;

[ContextMenu("Increase Score")]
public void addScore(int scoreToAdd)
 
{
    playerScore = playerScore + scoreToAdd;
    scoreText.text = playerScore.ToString();
}
public void restartGame()
{
    SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}

}

Context menus cannot have arguments. You can have the ‘Increase Score’ context menu, but you will have to either increase it by 1 (or some other value) or make multiple context menus that will allow you to build up a score. Having increments of 1, 10, 100 or 1, 5, 10, 50, etc.

You could reuse what you have and just put context menus on different methods

public void AddScore(int scoreToAdd)
{
    playerScore = playerScore + scoreToAdd;
    scoreText.text = playerScore.ToString();
}

[ContextMenu("Increase Score by 1")]
private void AddOneToScore() // you cannot pass arguments here
{
    AddScore(1);
}
[ContextMenu("Increase Score by 10")]
private void AddTenToScore() // you cannot pass arguments here
{
    AddScore(10);
}
// etc...

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms