Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- public class CamSurface : MonoBehaviour {
- public UrlFeeder Feeder;
- public string URL;
- public CamSurfaceController controller;
- private float GetRate;
- private float nextGet = 0f;
- private int succesFullTrick, maxSuccesFullTricks;
- public WWW CamWww;
- private void Start()
- {
- GetRate = controller.SearchingRate;
- GetRate = GetRate + Random.RandomRange(0,2);
- URL = Feeder.GetRandomUrl();
- maxSuccesFullTricks = 30;
- }
- IEnumerator GetTexture()
- {
- if (gameObject.GetComponent<MeshRenderer>().material.mainTexture == null)
- {
- URL = Feeder.GetRandomUrl();
- }
- if (succesFullTrick >= maxSuccesFullTricks)
- {
- URL = Feeder.GetRandomUrl();
- }
- Texture2D tex;
- tex = new Texture2D(4, 4, TextureFormat.DXT1, false);
- CamWww = new WWW(URL);
- yield return CamWww;
- if (CamWww.error != null)
- {
- URL = Feeder.GetRandomUrl();
- yield return null;
- } else {
- GetRate = controller.RefreshRate;
- CamWww.LoadImageIntoTexture(tex);
- CamWww.Dispose();
- if (tex.width <= 20)
- {
- yield return null;
- }
- else
- {
- succesFullTrick++;
- gameObject.GetComponent<MeshRenderer>().material.mainTexture = tex;
- }
- }
- }
- public void StopCoroutine()
- {
- StopCoroutine("GetTexture");
- }
- public void OnApplicationQuit()
- {
- print("quit");
- }
- louisvoid Update()
- {
- if (Time.time > nextGet)
- {
- StartCoroutine("GetTexture");
- print("starting");
- nextGet = Time.time + GetRate;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement