skip to Main Content

When I write a code in C# the unity console it does not show the output. The code editor is Visual Studio. Please give quick answer.

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

public class TestScript : MonoBehaviour
{
    // Start is called before the first fra
    void Start()
    {
        print("hello world");
    }

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

but the output is:

enter image description here
I searched on Google but I didn’t find the right answer

2

Answers


  1. The problem you are facing is that while the MonoBehavior.print method is a real method, you likely haven’t attached your script to an active game object and so the Start() method is never being called by the Unity Engine. To ensure it gets called, you can drag and drop the script file onto an active element’s inspector window that you have selected in the Hierarchy. Upon completing this action, you should see when you run the project you will get the "hello world" message. Ensure that in the Inspector window, the checkbox to the left of the game object’s name is checked (this means the element is active).

    If this solution doesn’t work for you, then you need to provide more information about your problem (e.g. what version of Unity are you working with).

    Login or Signup to reply.
  2. make sure you attached your script to a game object by going ‘add component’ on the inspector menu after selecting the game object

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search