using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Texture2DRaycastHit : MonoBehaviour
{
private Texture2D texture2DSpriteWithClouds;
private Vector2 mousePos = new Vector2();
private RectTransform rect;
// Start is called before the first frame update
void Start()
{
var rawImage = GetComponent<RawImage>();
rect = rawImage.GetComponent<RectTransform>();
texture2DSpriteWithClouds = rawImage.texture as Texture2D;
Color[] texture2dWithCloudsPixels = texture2DSpriteWithClouds.GetPixels();
}
// Update is called once per frame
void Update()
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(rect,
Input.mousePosition, Camera.main, out mousePos);
print("Mouse Pos X " + mousePos.x + " Mouse Pos Y " + mousePos.y);
}
}
脚本被附加到具有原始图像的对象,并且原始图像源图像是texture2D。
在纹理域中是s1。
1条答案
按热度按时间hmae6n7t1#
解决方案是在画布(原始图像在画布下)中将“渲染模式”更改为“屏幕空间-摄影机”,然后将摄影机指定给“渲染摄影机”字段。