Quantcast
Channel: Latest Questions by honikun
Viewing all articles
Browse latest Browse all 49

Trying to change a texture with picture from camera

$
0
0
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; } } }

Viewing all articles
Browse latest Browse all 49

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>