Skip to content

GameObjects & Transforms

Almost every script touches the scene through two handles: a GameObject (the thing) and its Transform (where it is). These behave exactly like they do in Unity — NexusScript exposes them as thin wrappers, so if you know Unity, you already know this page. The job here is to show how to reach a handle and the SocialScape‑specific notes.

Where this runs

Object moves, parenting, and SetActive run on each player's client and are not automatically networked. Moving a plain GameObject moves it for everyone who runs the script, which is fine for deterministic, script‑driven motion (a spinning coin, an opening door) — every client computes the same thing. For authoritative, owner‑moved objects use the world's networked‑object components instead (see World objects). For physics that must agree across clients, see Physics.

Getting a handle

You rarely call new on a GameObject. You get one of these ways:

public GameObject target;                 // 1. inspector slot — drag it in (preferred)
GameObject g = GameObject.Find("Coin");   // 2. by name (slow; cache the result)
GameObject lit = GameObject.FindWithTag("Spawn");
GameObject[] all = GameObject.FindGameObjectsWithTag("Enemy");
Transform t = transform;                  // 3. this object's own transform
Transform child = transform.GetChild(0);  // 4. walk the hierarchy
GameObject other = col.gameObject;        // 5. from a collider in OnTriggerEnter

Prefer inspector slots over Find

GameObject.Find scans the whole scene every call. Resolve references once in Start (or expose a public GameObject/Transform and drag it in) and store them in fields.

Transform — position, rotation, scale

A Transform holds world values (position, rotation, eulerAngles) and local values (relative to the parent: localPosition, localRotation, localScale). Setting any of these moves the object immediately.

transform.position = new Vector3(0, 2, 0);            // teleport in world space
transform.localPosition += new Vector3(0, 0.1f, 0);   // nudge up relative to parent
transform.rotation = Quaternion.Euler(0, 90, 0);      // face +X
transform.localScale = new Vector3(2, 2, 2);          // double size

Move and rotate by a delta (frame‑rate‑aware — multiply by Time.deltaTime):

protected override void Update()
{
    transform.Translate(new Vector3(0, 0, 2 * Time.deltaTime)); // forward 2 m/s
    transform.Rotate(new Vector3(0, 45 * Time.deltaTime, 0));   // spin 45°/s on Y
}

Aim at something and read direction vectors:

transform.LookAt(target.position);   // point +forward at a world position
Vector3 ahead = transform.forward;   // unit vectors: forward / right / up
Vector3 toGo  = transform.position + transform.forward * 3f;
Read / write Meaning
position · rotation · eulerAngles world‑space transform
localPosition · localRotation · localScale relative to parent
forward · right · up (read‑only) object's axis directions in world space
parent · childCount · GetChild(i) · name · tag hierarchy & identity

Parenting

SetParent re‑homes an object in the hierarchy. Local values are kept (the object visually jumps to the same local offset under the new parent), which is what you want when attaching props.

prop.transform.SetParent(transform);        // attach prop to this object
prop.transform.localPosition = Vector3.zero; // snap to the parent's origin
prop.transform.SetParent(null);             // detach back to the scene root

Activate / deactivate & layers

target.SetActive(false);                 // hide + disable (stops Update, colliders, render)
bool on = target.activeSelf;             // its own flag
bool live = target.activeInHierarchy;    // false if any ancestor is inactive
target.layer = LayerMask.NameToLayer("Interactable");

Spawning objects

You can create primitive shapes at runtime (no asset reference needed). They come with a collider already:

GameObject ball = GameObject.CreatePrimitive("Sphere");  // Cube, Sphere, Capsule, Cylinder, Plane, Quad
ball.transform.position = new Vector3(0, 5, 0);
ball.GetComponent<Renderer>().SetColor(Color.red);

To get a component off an object, use GetComponent<T>() — the gateway to Physics (Rigidbody, Collider), Rendering (Renderer, Light), UI, Audio (AudioSource), and Animation (Animator):

Rigidbody rb = ball.GetComponent<Rigidbody>();
Light lamp = lampObject.GetComponent<Light>();

Messaging

SendMessage calls a named method on the object's NexusScript(s) — handy for loose, one‑off signalling between scripts. (For typed, world‑wide events prefer GameSignal / World events.)

target.SendMessage("OnActivated");           // calls public void OnActivated() on target's scripts
target.BroadcastMessage("Reset");            // target + all its children

Quick reference

Group Calls
Find GameObject.Find · FindWithTag · FindGameObjectsWithTag · transform.GetChild
Create GameObject.CreatePrimitive(kind) · GetComponent<T>()
Transform write position · localPosition · rotation · localRotation · eulerAngles · localScale
Transform move Translate · Rotate · LookAt · SetParent
Transform read forward · right · up · parent · childCount · name · tag
State SetActive · activeSelf · activeInHierarchy · layer · tag · name
Messaging SendMessage · BroadcastMessage · SendMessageUpwards

→ Next: Math & vectors for the Vector3/Quaternion maths these calls take, or Physics to make objects collide and respond to force.