Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Mar 08, 2015 at 11:51 PM by KnightRiderGuy for the following reason:

found a solution

avatar image
0
Question by KnightRiderGuy · Feb 25, 2015 at 12:36 AM · c#webcamtexturevideotexturematerial renderer

Changing Video Cam Texture Material With Buttons

I have this script that allows video to be played on a plane, I was trying to figure out how to change the material on the plane the web cam video plays on because the effect is cool, but I'm not having a lot of luck. This us the Video player script I'm using:

 using UnityEngine; // 41 Post - Created by DimasTheDriver on July/22/2012 . Part of the 'Unity: capturing the video input from multiple webcams' post. Available at: http://www.41post.com/?p=4854.
 using System.Collections;
 
 public class MultipleWebCamPreview: MonoBehaviour 
 {
 
 
 
     //The texture that holds the video captured by the webcam
     private WebCamTexture webCamTexture;
     
     //An array that stores a reference to the names of all connected webcams
     private string[] nameWebCams;
     
     //The current webcam
     private int currentCam = 0;
     
     //The selected webcam
     private int selectedCam = 0;
     
     void Start()
     {
         //An integer that stores the number of connected webcams
         int numOfCams = WebCamTexture.devices.Length;
         
         //Initialize the nameWebCams array to hold the same number of strings as there are webcams
         this.nameWebCams = new string[numOfCams];
         
         //Get the name of each connected camera and store it into the 'nameWebCams' array
         for(int i = 0; i<numOfCams; i++)
         {
             this.nameWebCams[i] = WebCamTexture.devices[i].name;            
         }
         
         //Initialize the webCamTexture
         webCamTexture = new WebCamTexture();
         //Assign the images captured by the first available webcam as the texture of the containing game object
         renderer.material.mainTexture = webCamTexture;
         //Start streaming the images captured by the webcam into the texture
         webCamTexture.Play();
     }
     
     void OnGUI()
     {
         //Render the SelectionGrid listing all the cameras and save the selected one at 'selectedCam'
         selectedCam = GUI.SelectionGrid(new Rect(20,20,200,50), currentCam, nameWebCams, 1);
         
         //If the selected camera isn't the current camera
         if(selectedCam != currentCam)
         {
             //Assign the value of currentCam to selectCam
             currentCam = selectedCam;
             //Stop the streaming of captured images
             webCamTexture.Stop();
             //Assign a different webcam to the webCamTexture
             webCamTexture.deviceName = WebCamTexture.devices[currentCam].name;
             //Start streaming the captured images from this webcam to the texture
             webCamTexture.Play();
         }
     }
 
 
 }


and this is the script I came up with to change the material on the plane using buttons but as I say I can get the material to change but it does not do the same thing as when I play the scene and drag a material into the plane's material slot, only then do I get the effect I want????

 using UnityEngine;
 using System.Collections;
 
 public class VideoScreenManager : MonoBehaviour {
 
 
 
     //Material Reference
     public Material newMaterialRef01;
     public Material newMaterialRef02;
     public Material newMaterialRef03;
     public Material newMaterialRef04;
     public Material newMaterialRef05;
     public Material newMaterialRef06; //Default White Material
 
 
     public void  GoColor01(){
         renderer.material = newMaterialRef01;
 
     }
 
     public void  GoColor02(){
         renderer.material = newMaterialRef02;
         
     }
 
     public void  GoColor03(){
         renderer.material = newMaterialRef03;
         
     }
 
     public void  GoColor04(){
         renderer.material = newMaterialRef04;
         
     }
 
     public void  GoColor05(){
         renderer.material = newMaterialRef05;
         
     }
 
 
     public void  GoColor06(){
         renderer.material = newMaterialRef06;
         
     }
 }
 
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Material changes when i drag and drop it on object but doesnt through code? 1 Answer

WebGL VideoTexture not working 0 Answers

Playing Video When Clicked (Stay Paused In Scene) 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