Why does my script executes twice in Unity?

So it doesn’t matter what I do with my script, it doesn’t matter if it’s just 1 line, for ex:
Debug.Log(“Welcome to number wizard, yo”);
When I save it and press play in Unity it will show that twice in the Console. Same goes for inputs, if I press down, up, or enter key it inputs it twice. I’ve tried to look this up myself and find a solution but I can’t…

Any help would be appreciated.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NumberWizard : MonoBehaviour
{
    // Use this for initialization
    void Start()
    {
        int max = 1000;
        int min = 19;


        Debug.Log("Welcome to number wizard, yo");
        Debug.Log("Pick an number, don't tell me what it is...");
        Debug.Log("The highest number you can pick is: " + max);
        Debug.Log("The lowest number you can pick is: " + min);
        Debug.Log("Tell me if your number is higher or lower than 500");
        Debug.Log("Push up = higher, Push down = lower, Push Enter if correct");
    }
    

    // Update is called once per frame
    void Update()
    {
        //Detect when the up arrow key is pressed down
        if (Input.GetKeyDown(KeyCode.UpArrow))
            Debug.Log("Up Arrow key was pressed.");
        //Detect when the down arrow key is pressed down
        else if (Input.GetKeyDown(KeyCode.DownArrow))
            Debug.Log("Down Arrow key was pressed.");
        //Detect when the enter(return) arrow key is pressed down
        else if (Input.GetKeyDown(KeyCode.Return))
            Debug.Log("Enter key was pressed.");
    }
}

Hi William,

If a message appears twice even though it was expected once, it’s very likely that there is a duplicate of your script instance in your scene. Check all your game objects and remove the superfluous NumberWizard component.

1 Like

I did have another one in there, but it had no information in it. But once I deleted it, the problem resolved. :roll_eyes:

Thanks! :grin:

I’m glad the solution was that easy. :slight_smile:


See also:

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

Privacy & Terms