Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by gotmilk · Apr 15, 2010 at 07:40 PM · timevideocontrolstream

Create a switch that turns ON/OFF video streams. (in C#)

Hello i have this script.

using UnityEngine; using System.Collections;

public class WebCam : MonoBehaviour {

 public string url = "";

 void Start()
 {
     renderer.material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
     StartCoroutine(UpdateCam());
 }

 IEnumerator UpdateCam()
 {
     while (true)
     {
         Debug.Log("reloading webcam");
         WWW www = new WWW(url);
         yield return www;
         www.LoadImageIntoTexture((Texture2D)renderer.material.mainTexture);
     }
 }

}

I want to create a GUI switch that turns this stream on and off. The web cam material is streamed on the plane. My first solution was to just disable the plane render. But that still leaves the stream open and it takes resource that can be used somewhere else.

Then i edited the code so that it had a bool value on or off. If the value was false then it just skipped the while loop in my code. It worked only half way. Because my Update cam function is called on Start() it only initializes the true or false value and thats it. I turn my GUI switch off but nothing happens because the default value was already initialized in Start()

So i took my Update cam function and put it into Update() method. It worked perfectly. I could switch the stream on and off but since the update was called on every frame my application nearly freezed.

Since i am new to programming can anyone give me the pointers how to call that UpdateCam() function so that it only checks it once in a second. I know that there is Time.DeltaTime supposed to be in there but all this syntax thing is very new for me. Of course if you have even better solution then please tell me.

Thank you for your time.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by gotmilk · Apr 15, 2010 at 08:42 PM

i shall answer my own question. I came up with this and it works.

using UnityEngine;

using System.Collections;

public class streamScreen : MonoBehaviour { #region Fields //streamScreen myComponent; // public bool cameraOnOff = true; public string url = ""; float cameraUpdate = 0.1f; bool onOff = false;

#endregion

region Properties

endregion

region Functions

void Start() { renderer.enabled = true; // streamScreen myComponent = (streamScreen)GetComponent("cameraStream"); // myComponent = (streamScreen)GameObject.Find("streamScreen").GetComponent("cameraStream");

// myComponent.enabled = false;

 renderer.material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
 StartCoroutine(UpdateCam());

}

void Update() { if (onOff == false) { cameraUpdate = 0.1f; } else { cameraUpdate = 5f; // put very big number here to wait for millions of seconds to make a stream }

}

IEnumerator UpdateCam()
{ // while (cameraOnOff == true) while (true) { Debug.Log("reloading webcam"); WWW www = new WWW(url); yield return www; www.LoadImageIntoTexture((Texture2D)renderer.material.mainTexture); yield return new WaitForSeconds(cameraUpdate);

 }

}

public void switchCamera() { // renderer.enabled = true;

 onOff = !onOff;
 Debug.Log("You released the RIGHT button");

}

endregion

/code>

}

Thank you for your time. :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to make camera position relative to a specific target. 1 Answer

Movement over Time 2 Answers

Ustream Support 1 Answer

RTMP Video Stream in Unity 2 Answers

Advanced Video Time Manipulation Possible? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges