Add Component#
Game Object / Component / Add Component
Description#
Adds a new component to the specified Game Object
Parameters#
| Name | Description |
|---|---|
| Game Object | The game object reference |
| Component | The type of component to add |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Title("Add Component")]
[Image(typeof(IconCubeOutline), ColorTheme.Type.TextLight, typeof(BadgePlus))]
[Description("Adds a new component to the specified Game Object")]
[Category("Game Object/Component/Add Component")]
[Parameter("Game Object", "The game object reference")]
[Parameter("Component", "The type of component to add")]
[Keywords("Insert")]
[Serializable]
public class InstructionCoreGameObjectAddComponent : Instruction
{
[SerializeField] private GetGameObject m_GameObject = new GetGameObject();
[SerializeField] private TypeReferenceComponent m_Component = new TypeReferenceComponent();
protected override string GetTitle(GameObject source)
{
string component = TextUtils.ThemeAsConstant(this.m_Component.ToString());
return $"Add {component} to {this.m_GameObject}";
}
protected override Awaitable Run(Args args)
{
GameObject gameObject = this.m_GameObject.Get(args);
if (gameObject != null)
{
gameObject.Add(this.m_Component.Type);
}
return Done;
}
}
}