Guides
Log In

GameObjects and Components

In games, it is very common to create new objects or to modify or add components to existing ones.

ZEPETOScript supports the same interface as that used in the Unity script.

Creating and removing game objects:

// GameObject Create
const tempObj = new GameObject();
const obj = Object.Instantiate(tempObj);
 
// GameObject Destroy
Object.Destroy(obj);

To get GameObjects components or add new ones, use GetComponent or AddComponent.

// GetComponent with Generic
const myTransform = this.GetComponent<Transform>();
 
// AddComponent with Generic
const animator = this.gameObject.AddComponent<Animator>();

Check the full code example for the GameObject Component.

import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { GameObject, Object, Transform, Animator, Light } from 'UnityEngine';

export default class GameObjectSample extends ZepetoScriptBehaviour {

    Start() {
        // GameObject Create
        const tempObj = new GameObject();
        const obj = Object.Instantiate(tempObj);

        // GameObject Destroy
        Object.Destroy(obj);

        // GetComponent with Generic
        const myTransform = this.GetComponent<Transform>();

        // AddComponent with Generic
        const animator = this.gameObject.AddComponent<Animator>();
    }
}

Click the links below to learn more about the Unity GameObjects and Components offered by ZEPETOScript.



πŸ“˜

Creating GameObjects

https://docs.unity3d.com/2020.3/Documentation/ScriptReference/Object.Instantiate.html

πŸ“˜

Destroying GameObjects

https://docs.unity3d.com/2020.3/Documentation/ScriptReference/Object.Destroy.html

πŸ“˜

Using components

https://docs.unity3d.com/kr/current/Manual/UsingComponents.html