---
title: Write and attach scripts
product: Unity Spark
canonical: https://docs.unity.com/en-us/unity-spark/create/build/scripts/write-scripts
last_updated: 2026-12-01
generated_at: 2026-12-01T21:01:36.643Z
locale: en-us
---

# Write and attach scripts

> Open scripts in the Script window, attach them to objects, and ask the assistant to write them for you in Unity Spark.

The assistant writes most scripts for you, but you can also open, read, and change them yourself in the **Script** window, and attach them to the objects they control. For more information about how scripts work, refer to [Introduction to scripts in Unity Spark](/unity-spark/create/build/scripts/about-scripts.md).

For a description of each control, refer to [Script window reference](/unity-spark/create/build/scripts/script-window-reference.md).

## Open the Script window

To add the **Script** window to your workspace:

1. In any window group, select **Add window** (**+**).
2. Select **Script**, or search for it in the **Search windows** field.

To start a new script, select **New script** (**+**).

To open an existing script, select **Open a script** (**+**), then select the script. You can also double-click a script in the [Project window](/unity-spark/create/assets/manage/project-window-reference.md) to open it.

When the assistant works on a script, it shows a label in the [Scene view](/unity-spark/create/build/scenes/scene-view/scene-window-reference.md). Select the label's text to open that script in the **Script** window. For more information, refer to [Follow the scripts and assets the agent works on](/unity-spark/create/assistant/follow-agent/follow-agent-work.md#follow-the-scripts-and-assets-the-agent-works-on).

## Attach a script to an object

To attach a script to an object, do one of the following:

### Drag and drop the script onto the object

To attach a script to an object:

1. In the **Project** window, select the script.
2. Drag the script onto the object in the [Scene view](/unity-spark/create/build/scenes/scene-view/scene-window-reference.md) or the [Hierarchy window](/unity-spark/create/build/objects-prefabs/hierarchy-window-reference.md).

### Use the Inspector window to add the script as a component

To attach a script to an object using the **Inspector** window:

1. Open the **Inspector** window (**Add Window** (**+**) > **Inspector**).
2. Select the object in the [Scene view](/unity-spark/create/build/scenes/scene-view/scene-window-reference.md) or the [Hierarchy window](/unity-spark/create/build/objects-prefabs/hierarchy-window-reference.md).
3. In the **Inspector** window, select **Add Component** > **Scripts**.
4. Select the script.

For more information, refer to [Add a component](/unity-spark/create/build/components/manage-components.md#add-a-component).

## Ask the assistant to write scripts

The assistant can write and change scripts for you. Describe the behavior you want. For example, you can enter the following prompts:

* `Put a spinning coin on each platform and count the coins I collect.`
* `When the player clicks Play, load the Level 1 scene.`

The assistant can make mistakes so always review its changes:

1. Review the scripts.
2. Play your game to test them.
3. If needed, ask for changes.

If your game logs errors, enter `/fix-errors` in the [Chat window](/unity-spark/create/assistant/chat-window-reference.md). For more information about fixing errors, refer to [Fix errors with the assistant](/unity-spark/create/test-debug/find-fix-errors.md#fix-errors-with-the-assistant).

## Additional resources

* [Script window reference](/unity-spark/create/build/scripts/script-window-reference.md)
* [Introduction to scripts in Unity Spark](/unity-spark/create/build/scripts/about-scripts.md)
* [Components, tags, and layers](/unity-spark/create/build/components.md)
* [Find and fix errors with the Console window](/unity-spark/create/test-debug/find-fix-errors.md)
