- Home /
SetPixels PROBLEM (trying to put decals)
Hi, basically I want to put transparent texture onto base texture with SetPixels function. I'm using raycast to get mesh texture coordinates. Please help :) Here is the code:
using UnityEngine;
using System.Collections;
public class DecalSystem : MonoBehaviour
{
public Texture2D layerTex; //Base texture
public Texture2D decalTex; //Transparent texture
private Camera cam; //Camera
private Ray ray; //Ray
private RaycastHit hit;//Raycast
void Start()
{
cam = Camera.main;
}
void Update()
{
if (!Input.GetMouseButtonDown(0))
return;
ray = cam.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit))
{
if(hit.collider.name == "Board")
{
Vector2 layerUV = new Vector2(hit.textureCoord.x, hit.textureCoord.y);
//// Dont work from here:
// Color[] decalPixels = new Color[decalTex.width * decalTex.height];
// layerTex.SetPixels(layerUV.x, layerUV.y, //DONT KNOW, //DONT KNOW, decalPixels);
////
layerTex.Apply();
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Use SetPixels, but dont set unvisible Pixels 1 Answer
getPixel/setPixels or stencil eraser brush 2 Answers
How can I show my SetPixels() texture changes without having to zoom my orthographic camera? 1 Answer
Resetting a Material's Texture After GetPixels/SetPixels 1 Answer
getPixel, setPixel and 2dTextures- Help! 0 Answers