Skip to content

Instantly share code, notes, and snippets.

@Santarh
Created March 10, 2012 17:13
Show Gist options
  • Save Santarh/2012153 to your computer and use it in GitHub Desktop.
Save Santarh/2012153 to your computer and use it in GitHub Desktop.
UnityWebPlayer - Texture CHANGE!!!! http://dl.dropbox.com/u/11910973/Unity/nyan/index.html
JavaScript部分
function set_texture()
{
var unity = GetUnity();
var url = document.my_form.url.value;
unity.SendMessage("Plane", "set_texture", url);
}
HTML部分
<form name="my_form">
<input type="url" name="url" value="http://" id="url">
<input type="button" value="好きな画像に変更できるゾ" onclick="set_texture()">
</form>
using UnityEngine;
using System.Collections;
public class TestTexture : MonoBehaviour
{
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
this.transform.RotateAroundLocal( Vector3.forward, 1.0f * Time.fixedDeltaTime );
}
IEnumerator set_texture( string url )
{
WWW www = new WWW( url );
yield return www;
this.renderer.material.mainTexture = www.texture;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment