public class Avatar : CommunicationBridge
// Avatar reference
public Avatar MyAvatar;
void Awake() {
// Event for avatar possessed
MyAvatar.OnPossessed.AddListener(Possessed);
// OnUnpossessed is called on unposses and client disconnect.
}
// Log username on Possession
void Possessed(User user) => Debug.Log("Possessed by " + user.Name);
public Avatar MyAvatar;
void Awake() {
MyAvatar.OnPossessed.AddListener(Possessed);
}
void Possessed(User user) {
// Return if not user's client.
if (user != MyAvatar.Multiplayer.Me) return;
// Set camera as child to object
Camera myCamera = Camera.main;
myCamera.transform.position = transform.position + new Vector3(0, 0.4f, 0);
myCamera.transform.SetParent(transform);
// Lock cursor
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
IsMe | True when the Avatar represents the local player. |
IsOwner | True when the Avatar represents the local player. |
Owner | User that posses the Avatar. Null when unprocessed. |
Possessor | User that posses the Avatar. Null when unprocessed. |
Possessed(User) | The possessed method can be used to set owner of a avatar. |
Possessed(Boolean, User) |
The possessed method can be used to set owner of a avatar.
(Overrides CommunicationBridgePossessed(Boolean, User)) |
Serialize | Serializes transform and synchronizables. |
ToString |
Get name and index in a string.
Returns "Unprocessed" when IsPossessed is false.
(Overrides Object.ToString) |
Unpossessed | (Overrides CommunicationBridgeUnpossessed) |
Unserialize | Unserialize transform and synchronizables. |
IsPossessed | True when possessed by a User. |
IsPossessor | True when the Avatar represents the local player. |
OnPossessed | On Avatar get posses by new User. |
OnUnpossessed | On Avatar unpossess. |