unity 改变纹理像素点的颜色

using UnityEngine;
using System.Collections;

public class SendLine : MonoBehaviour {

    public Vector3 targetPoint;
    private Transform MyTransform;
    public Texture2D TextureMap;
	void Start () 
    {
        MyTransform = GetComponent();
	}
	
	void Update () 
    {
        sendLineMeth();
	}

    void sendLineMeth()
    {
        RaycastHit hit;
        if( Physics.Raycast(MyTransform.position, -MyTransform.up,out hit,10f))
        {
           targetPoint= hit.point;
           Debug.DrawLine(MyTransform.position, targetPoint);
            //涂色
           Vector2 pixelUV = hit.textureCoord;
           pixelUV.x *= TextureMap.width;
           pixelUV.y *= TextureMap.height;
           TextureMap.SetPixel((int)pixelUV.x, (int)pixelUV.y,Color.red);
           Debug.Log(pixelUV);
           TextureMap.Apply();
        }
    }
}

你可能感兴趣的:(unity3d基础)