The Unity script needs the Editor and the setup listed below. The separate C# companion practice runs in SharpRune without UnityEngine.
A component script belongs to an engine project
Unity6.0, identified by the 6000.0 documentation, is this course’s Editor baseline. A Unity component script is imported into an engine project and attached to a GameObject. Its supported callbacks are invoked by Unity, rather than by a console program’s top-level entry point. The separate C# practice in SharpRune remains an ordinary .NET9 program. Learning both forms is useful, but the boundary matters: running a portable lab does not create a Unity scene, render a camera, or prove that an Editor imported a script.
Create the asset, attach the component, then enter Play
Save the supplied engine code as HelloUnity.cs, retaining the public HelloUnity class. Let the Editor compile without errors, create an active empty GameObject called Greeter, and attach the script. The Inspector exposes message through SerializeField. Start logs that configured message when the enabled component reaches its initial Play-mode start. The code is deliberately a conventional class compatible with Unity’s documented C#9 environment: no file-scoped namespace, record dependency, fake UnityEngine namespace, or top-level executable statements are required in the Editor script.
Read what the portable result actually verifies
The companion evaluates Matches for two filename/type-name pairs. HelloUnity.cs and HelloUnity have equal names after removing the .cs suffix, so the first result is True. Different.cs and HelloUnity do not match, giving False. This is an ordinary string rule, not a complete C# identifier validator or a replacement for Unity’s importer. Its value is the small explicit contract: check one setup assumption independently, then verify the real asset through the actual Editor Console and Inspector instead of presenting a simulated engine as execution evidence.
Separate source defaults from stored scene configuration
Changing the source initializer does not necessarily replace a value already serialized on an existing component. The Inspector may still show the scene’s stored message, while a newly added component begins with the new default. A missing log can also come from an inactive object, a disabled script, compilation errors, or a Console filter. Diagnose those as different setup states. Do not construct a MonoBehaviour with new to bypass attachment; let Unity create and manage the component through its supported object workflow.
Practice: change the configured message without changing the type
Set message to a distinctive phrase in the Inspector, save the scene, enter Play mode, and identify the single log from Greeter. Stop, change the source initializer, and compare the existing component with a newly attached copy. Predict which value each instance owns before entering Play again. This exercise isolates serialized configuration from source text and makes it clear that the message printed by Start is the instance’s configured field, not an automatic rereading of the initializer at every callback.
- Keep a clean Console and select the log context to identify which component produced it.
- Rename both the file and type together in a separate experiment, then wait for compilation before judging attachment.
Practice: define the small filename contract precisely
For an independent portable exercise, test an empty name, a file without the .cs suffix, and a differently cased suffix. Record which forms the current ordinal string rule accepts. Then redesign Matches to return a named reason for a mismatch instead of only a Boolean, without claiming it validates an entire Unity project. Keep the test data separate from the Editor experiment: a passing filename check cannot prove that the class derives from MonoBehaviour, is attachable, or has error-free dependencies.
- The current lab accepts exactly its stated case-sensitive suffix and name relationship.
- Use the real Editor to verify import, inheritance and attachment after the text-level check passes.
Keep the two execution paths visible
The course provides an actual engine script with specific scene steps and a separately runnable C# lab. Each has a different verification boundary. The lab’s deterministic output is True then False; the Editor script’s intended behavior is one configured Start message on an active enabled instance. No Unity Editor is installed in this validation environment, so its code is documentation-checked and syntax-checked rather than claimed as Editor-run. Preserve that distinction when moving from a small greeting to physics, input and packaged Player behavior.
- Use the pinned 6000.0 documentation rather than assuming this lesson identifies the newest Unity release.
- Check compilation, attachment, active state and enabled state independently.
- The Open C# practice action runs the portable lab, not the Unity component.
Unity Editor example
Set up in Unity 6
- Open or create a Unity6.0 (6000.0) project; this course does not install an Editor.
- Create Assets/Scripts/HelloUnity.cs and replace its contents with the Unity script, keeping the filename and class name.
- Wait for a clean compilation, create an empty active GameObject named Greeter, and attach HelloUnity.
- Set message in the Inspector, save the scene, enter Play mode, and inspect the Console.
- Change message, stop and re-enter Play mode; distinguish saved scene data from the source default.
HelloUnity.cs
Download Unity script ↗using UnityEngine;
public sealed class HelloUnity : MonoBehaviour
{
[SerializeField] private string message = "Hello from Unity6";
private void Start()
{
Debug.Log(message, this);
}
}
What to observe in Unity
One message is logged from Start for the enabled component in Play mode. No Unity execution occurs in the SharpRune companion console.
The console practice below isolates the C# logic. It does not run a Unity scene or emulate Unity engine callbacks.
C# companion practice
using System;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
Console.WriteLine(Matches("HelloUnity.cs", "HelloUnity"));
Console.WriteLine(Matches("Different.cs", "HelloUnity"));
bool Matches(string file, string type) => file.EndsWith(".cs", StringComparison.Ordinal) && file.Substring(0, file.Length - 3) == type;
C# practice output
True False
The console lab checks text only; run the Unity script inside an actual Editor scene.