unity 改变纹理像素点的颜色

来源:互联网 发布:如何让mac不休眠 编辑:程序博客网 时间:2024/05/22 03:02
using UnityEngine;using System.Collections;public class SendLine : MonoBehaviour {    public Vector3 targetPoint;    private Transform MyTransform;    public Texture2D TextureMap;void Start ()     {        MyTransform = GetComponent<Transform>();}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();        }    }}

0 0
原创粉丝点击