The NetworkTransform component allows you to position, rotate, and scale GameObjects on the server and have the changes automatically applied on each player's client.
Overview
CubeManager.ts
export default class CubeManager extends AirshipSingleton {
// This is a reference to a prefab with NetworkIdentity and NetworkTransform
// components
public Cube: GameObject;
// This is a reference to an instantiated cube
private cubeInstance?: GameObject;
public override Start(): void {
if (!Game.IsServer()) return;
// Spawn a cube on the server
this.cubeInstance = Object.Instantiate(
this.Cube,
new Vector3(0, 1, 0),
Quaternion.identity
);
NetworkServer.Spawn(this.cubeInstance);
}
public override Update(dt: number): void {
if (!Game.IsServer() || !this.cubeInstance) return;
// Rotate the cube on the server
this.cubeInstance.transform.Rotate(Vector3.up, 10 * dt);
}
}
The NetworkTransform component can be added to any through the "Add Component" menu.
NetworkTransform requires a component to function properly.
When you spawn a NetworkIdentity, you can optionally specify an owner. The player who has ownership of a NetworkIdentity with a component has the authority to control the of the parent GameObject. All Transform updates made by the owner are applied on the server, and then sent to and applied on every other player's client.