Hello,
I would like to use the GUI button to load a new game file in a webplayer. The documentation for WWW.LoadUnityWeb and most WWW is in Javascript only for some reason, and I could not find any good examples. I am a bit new at coding so be nice please :)
Below is the basic button I would be using:
using UnityEngine;
using System.Collections;
public class interface1 : MonoBehaviour {
void OnGUI(){
if (GUI.Button(new Rect(Screen.width / 2, Screen.height / 10, 100, 25), "Load Game 1"))
Debug.Log("Clicked to load");
}
}
Thank you!
Here is the example translated into C#. Instead of using "Start," It uses a coroutine "StartLoad". So in your GUI Button, call StartCoroutine(StartLoad);
The stuff with the guiTexture is not important, it's used to display a loading bar.
void OnGUI()
{
if (GUI.Button(new Rect(Screen.width / 2, Screen.height / 10, 100, 25), "Load Game 1"))
{
StartCoroutine("StartLoad");
Debug.Log("Clicked to load");
}
}
// Streams a .unity3d file and displays the progress in a GUI texture.
// You need to make sure the GUI texture is set up to have a pixel inset.
IEnumerator StartLoad () {
// Store the original pixel inset
// and modify it from there.
Rect originalPixelRect = guiTexture.pixelInset;
// Update the progress bar by scaling the gui texture
// until we reach the end
WWW stream =
new WWW ("http://www.unity3d.com/webplayers/Lightning/lightning.unity3d");
while (!stream.isDone) {
guiTexture.pixelInset.xMax = originalPixelRect.xMin
+ stream.progress * originalPixelRect.width;
yield return null;
}
// Update it one last time before loading
guiTexture.pixelInset.xMax = originalPixelRect.xMax;
stream.LoadUnityWeb();
}