Skip to main content
Glama
CreateGameObjectCommand.cs1.86 kB
using System; using UnityEngine; using UnityMCP.Client.Editor.Logging; namespace UnityMCP.Client.Editor.Commands { /// <summary> /// Command for creating a GameObject /// </summary> public class CreateGameObjectCommand : CommandBase { private readonly string _code; /// <summary> /// Create a new CreateGameObjectCommand /// </summary> /// <param name="code">The code to execute</param> /// <param name="resultVariableName">The variable name to store the result in, if any</param> public CreateGameObjectCommand(string code, string resultVariableName = null) : base(resultVariableName) { _code = code; } /// <summary> /// Execute the command and return the result /// </summary> /// <param name="context">The command context</param> /// <returns>The result of the command execution</returns> public override object Execute(CommandContext context) { // This is a simple implementation that creates a GameObject // In a real implementation, you would parse the code to extract parameters // For now, we'll just create a GameObject with a default name var gameObject = new GameObject("CommandCreatedObject"); // Log the creation Debug.Log($"[Unity MCP] Created GameObject: {gameObject.name}"); AILoggerStatic.Log("unity-create-result", new { gameObject = gameObject.name }); // Store the result in the context if a variable name was provided if (!string.IsNullOrEmpty(ResultVariableName)) { context.SetVariable(ResultVariableName, gameObject); } // Return the GameObject return gameObject; } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TSavo/Unity-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server