--the below script checks if we are in Unity editor or in SS--this way we can provide an alternative--(Example: if we're using a function that doesn't work in Unity editor)thisGameObject = Space.Host.ExecutingObjectif Space.InEditor thenavatarUsername ="Player Name"elseavatarUsername = Space.Scene.GetAvatar(thisGameObject.Owner).Username --example: this doesn't work in EditorendSpace.Log(avatarUsername)
Version
int Versionget
Returns the version of the viewer this script is running in
--the below script will search through the Scripting Runtime's resources--and return the first instance of an Animation Clip--[You need to add a few resources to the scripting runtime and make one of them an animation]resources = Space.Resourcesfor i =1, #resources doif resources[i].Type =="AnimationClip" then Space.Log("Resource #".. i .." is an Animation Clip. The resource name is: " .. resources[i].Name)breakendend
Time
float Timeget
Returns time at the beginning of this frame.
floatTime = Space.Time
--this script will update a UIText object with the current local time without using a coroutine--(example: clock )--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]rateUpdate =1.0nextUpdate =0.0text = Space.Host.GetReference("Text").UITextOnUpdate=function()if Space.Time > nextUpdate then nextUpdate = Space.Time + rateUpdate text.Text = Space.LocalTimeend }Space.Host.ExecutingObject.OnUpdate(OnUpdate)
ServerTime
string ServerTimeget
Returns current server time.
serverTime = Space.ServerTime
--this script will update a UIText object with the current server time (UTC)--(example: clock)--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]text = Space.Host.GetReference("Text").UITextco=function()whiletruedo text.Text = Space.ServerTimecoroutine.yield(1)endendSpace.Host.StartCoroutine(co)
LocalTime
string LocalTimeget
Returns current local time.
localTime = Space.LocalTime
--this script will update a UIText object with the current local time--(example: clock)--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]text = Space.Host.GetReference("Text").UITextco=function()whiletruedo text.Text = Space.LocalTimecoroutine.yield(1)endendSpace.Host.StartCoroutine(co)
LoginTime
float LoginTimeget
Returns how long player has been logged in (in seconds).
loginTime = Space.LoginTime
--this script will update a UIText object with how long the user has been logged in (in seconds)--(example: clock)--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]text = Space.Host.GetReference("Text").UITextco=function()whiletruedo text.Text = Space.LoginTimecoroutine.yield(1)endendSpace.Host.StartCoroutine(co)
ServerTimeUnix
int ServerTimeUnixget
Returns the server time unix timestamp.
serverTimeUnix = Space.ServerTimeUnix
--this script will update a UIText object with the current server time unix timestamp--(example: clock)--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]text = Space.Host.GetReference("Text").UITextco=function()whiletruedo text.Text = Space.ServerTimeUnixcoroutine.yield(1)endendSpace.Host.StartCoroutine(co)
LocalTimeUnix
int LocalTimeUnixget
Returns the local time unix timestamp.
localTimeUnix = Space.LocalTimeUnix
--this script will update a UIText object with the current local time unix timestamp--(example: clock)--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]text = Space.Host.GetReference("Text").UITextco=function()whiletruedo text.Text = Space.LocalTimeUnixcoroutine.yield(1)endendSpace.Host.StartCoroutine(co)
DeltaTime
float DeltaTimeget
The completion time in seconds since the last frame.
deltaTime = Space.DeltaTime
--the below script rotates an object around Y axis but uses DeltaTime --to make sure it's not dependant on client's Framerate (FPS)--this way the object rotates per second not per frame--(Example: Important movement in OnUpdate)thisGameObject = Space.Host.ExecutingObjectOnUpdate=function()currentY = thisGameObject.WorldRotation.EulerAngles.YnewRotation = Quaternion.Euler(0, currentY +1* Space.DeltaTime, 0) --We multiplied 1 by Space.DeltaTimethisGameObject.WorldRotation = newRotationendthisGameObject.OnUpdate(OnUpdate)
PreviewServer
bool PreviewServerget
Return true if in preview server.
isInPreview = Space.PreviewServer
--this script will update a UIText object with "preview" or "live" depending--whether we are on preview server or live server--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]text = Space.Host.GetReference("Text").UITextOnUpdate=function()if Space.PreviewServer then text.Text ="Preview"else text.Text ="Live"endendSpace.Host.ExecutingObject.OnUpdate(OnUpdate)