hi my dear friends
i want to have a button which when clicked webcamera run and can shot and capture picture … then use that picture as texture of some of my models …
it means that i want to give my customers this ability to change the model texture via their mobile camera
is it possible ?
im very poor in programing … please explain it very clearly and simple
thanks alot
For the usage of a webcam:
You have to use a WebCamTexture
Here is a ready to use script example.
You just have to copy the content of the example in a new C# script (the new script file have to be called “ExampleClass”).
Then attach the script on a plane or a quad you can create within Unity.
Now about your models texture shot thing, it’s easy, but it get way more complicated when you want your models to actually look good, depending on what you want to do.
To achieve that you just have to take a picture and apply the picture texture on the material you want.
i used this code and every thing is good …but i have some other questions … it takes a shot and saved it in drive C …
i want to publish my app for android and ios …
which path should i assign in this part of code that i can load it for texture !
private string _SavePath = "C:/WebcamSnaps/"; //Change the path here!
and for loading image it means that i have to use this code:
// Add this script to a GameObject. The Start() function fetches an
// image from the documentation site. It is then applied as the
// texture on the GameObject.
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public string url = "https://docs.unity3d.com/uploads/Main/ShadowIntro.png";
IEnumerator Start() {
Texture2D tex;
tex = new Texture2D(4, 4, TextureFormat.DXT1, false);
WWW www = new WWW(url);
yield return www;
www.LoadImageIntoTexture(tex);
GetComponent<Renderer>().material.mainTexture = tex;
}
}
and change the url to my path ?
something like this:
public string url = Application.persistentDataPath+"/0.png";
??
You already got help: You were pointed to the tutorials!
Understand that this issue you’re asking us to solve is not the only one you’re going to run into. And you can’t just come ask someone to give you code each time something doesn’t work. Well, you can, but don’t expect people to do it.
If you want to be a game developer, you need to learn how to develop. That means either learning how to write code, or learning how to use a visual scripting tool (and accepting the things you sacrifice when you do so). It’s hard work, and no one can do it for you.
When you run into specific issues and show us that you’re working to solve it but need help, or you need further direction after you’ve followed the steps advised, we’ll be here and will be happy to assist.