Objects and components

A script reaches the objects of its world through GameObject, Transform and the components, with Unity's names. One C# object stands for each object of the world, so == compares the objects themselves.

csharp
using NodeWorld.Flux;

namespace MyWorld
{
    public class LampSwitch : FluxScript
    {
        public GameObject lamp;   // set from the scene

        protected override void Start() => Interaction.SetInteractable(gameObject, true);

        protected override void OnInteract()
        {
            lamp.SetActive(!lamp.activeSelf);
            var shade = lamp.transform.Find("Shade");
            if (shade != null) shade.localScale = lamp.activeSelf ? Vector3.one : new Vector3(1f, 0.5f, 1f);
        }
    }
}

Find an object

CallFinds
a field set from the scene (public GameObject door;)the object you dropped on the FL# Script component: the simplest and the fastest
GameObject.Find("Door")an object of the world by name
GameObject.FindPath("Bar/Counter/Door")the object at this path from a root of the scene
transform.Find("Hinge/Door")a child at this path below a transform
transform.GetChild(i), childCount, parent, rootthe hierarchy

Your scripts only see the objects of your world: those of your scene and those your scripts make. The avatars, portals, photo cameras and voices NodeWorld puts in your scene are not found (what a script cannot block).

The GameObject

  • name, tag (CompareTag("Bee")), layer (0 to 30: layer 31 is NodeWorld's interface, see layers). Setting a tag that the project's Tags and Layers does not have is refused: The tag 'Bee' is not defined in this world.
  • SetActive(bool), activeSelf, activeInHierarchy. A script on an inactive object gets no Update (see callbacks).
  • GetComponent<T>(), GetComponents<T>(), GetComponentInChildren<T>(), GetComponentsInChildren<T>(includeInactive).

The transform

position, rotation, localPosition, localRotation, localScale, lossyScale, eulerAngles, localEulerAngles, forward, up, right, localToWorldMatrix, worldToLocalMatrix, and Unity's methods: Translate, Rotate, LookAt, SetPositionAndRotation, TransformPoint, InverseTransformPoint, TransformDirection, TransformVector and their inverses, SetParent, GetSiblingIndex, SetSiblingIndex, SetAsFirstSibling, SetAsLastSibling, IsChildOf.

Moving an object here moves it for this player only. For every player, see synced objects and values.

The components a script can use

GetComponent<T>() works with these types; another type throws A FL# script cannot get the component <type>.

ComponentPage
Transform, RectTransformthis page, UI
Rigidbody, Collider, BoxCollider, SphereCollider, MeshColliderphysics
Renderer, LineRenderer, TrailRenderer, MeshFilter, Camera, Light, ParticleSystem, Animator, Volume, LODGroup, ReflectionProbe, ParentConstraintcameras, materials and effects, meshes made by scripts
AudioSourcesound
Canvas, CanvasGroup, Text, Image, Button, Slider, Toggle, Dropdown, InputField, ScrollRect, ScrollbarUI

Every other component of your scene (a reverb zone, a joint, a Timeline…) works as you set it in Unity; a script does not change it.

Copy and destroy

  • Object.Instantiate(original, parent) and Object.Instantiate(original, position, rotation, parent) copy an object of your world, with its children, for this player only. The FL# scripts of the copy are created right after the current callback. A copy that every player sees is spawned for the room.
  • Object.Destroy(obj) destroys what your scripts made: a copy, a camera, a render texture, a mesh, a video player, a batch. Given a component, it destroys its object. The scripts of a destroyed object get OnDestroy.

An object of your scene is not destroyed: turn it off with SetActive(false). The calls say so in the log: A FL# script can destroy only the objects it created., A FL# script can copy only the objects of its world.