- Home /
Trying to change a texture with picture from camera
On android i'm using WebCamTexture to take a photo(GetPixel), so i use this code, i want that the player can change the camo texture of my weapon with his camera, this is just a test, i know how i will make the interface, but the code is not working, i'm using one cube to show my camera, it work, the problem is, after pressing Fire1(LeftCtrl) it supposed to take a photo and replace the texture from the another cube, the first cube is just like a plane on a GUI to show the player what the camera is taking, and the another cube is supposed to be like a gun, before testing in a real gun i want this code to work, but i don't know the problem.
 using UnityEngine;
 using System.Collections;
 
 public class ChangeTextureWCam : MonoBehaviour {
 
     public int cameraWidth = 640;
     public int cameraHeight = 480;
     public Texture2D snap;
     public WebCamTexture wct;
     public GameObject anotherCube;
     void Start() {
         wct = new WebCamTexture(2000, 2000, 30);
         renderer.material.mainTexture = wct;
         wct.Play();
     }
     void Update(){
         if(Input.GetButtonDown("Fire1")){
             snap.SetPixels(wct.GetPixels());
             snap.Apply();
             anotherCube.renderer.material.mainTexture = snap;
         }
     }
 }
 
Answer by fifthknotch · Mar 08, 2014 at 04:38 PM
I believe webCamTextures will not do what you are trying to do. According to the docs:
Description:
WebCam Textures are textures onto which the live video input is rendered.
Yes, but it has a code called GetPixel that in terms take the pixels of this live video and turns that into a photo that can be saved.
Your answer
 
 
             Follow this Question
Related Questions
Camera.main.WorldToScreenPoint(touch.position). Help !!! 1 Answer
Smooth Follow Camera Rotate on Z-Axis? 2 Answers
Unity editor style camera script 1 Answer
Google VR not working with two cameras 0 Answers
Detect Android Rear Camera 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                