Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

"No overload for method 'addScore' takes 1 arguments" but there is an argument

Discussion in 'Getting Started' started by ZiKeng54, May 31, 2023.

  1. ZiKeng54

    ZiKeng54

    Joined:
    Dec 7, 2022
    Posts:
    1
    Alright, first of all, please do not kill me for the extremely probable stupidness of this thread. I'm following the GMTK unity tutorial and the method "addScore" should have an integer as argument, which it has (line 25), there is no error showing up on visual studio but unity says there is, this is the code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PipeMiddleScript : MonoBehaviour
    6. {
    7.     public LogicScript logic;
    8.  
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.      
    19.     }
    20.     private void OnTriggerEnter2D(Collider2D collision)
    21.     {
    22.         if (collision.gameObject.layer == 3)
    23.         {
    24.            //this is where the error shows up
    25.             logic.addScore(1);
    26.         }
    27.     }
    28. }
    29.  
    And here's the other code which defines addScore:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class LogicScript : MonoBehaviour
    7. {
    8.     public int playerScore;
    9.     public Text scoreText;
    10.  
    11.     [ContextMenu("Increase Score")]
    12.     public void addScore(int scoreToAdd)
    13.     {
    14.         playerScore = playerScore + scoreToAdd;
    15.         scoreText.text = playerScore.ToString();
    16.     }
    17. }
    18.  
    Again, please don't kill me, i beg of you, and thanks for your time.

    Also how do i get the yellow square thingy that says "Question" on my thread? I thought it would be just writting "Question" on the tags.
     
  2. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    1,026
    Don't worry about it really, although you know what they say "ask a daft question, you might get an even dafter answer" :D
     
  3. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    431
    Debugging the code is a daily task for programmers. It is a skill you need to train.

    A simple solution is just to put Debug.Log in every logic part of you're code. Now console works as the primitive profiler to reduce the search area.

    Edit: The code looks fine (something you can always do another way), so the problem is a logic error. Something behaves another way you expected.
     
    Last edited: Jun 1, 2023