Hey guys I have a bit of a doosey here. Code (csharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class PieChartTriggers : MonoBehaviour { Color[] Data; public Image image; public int Width { get { return image.sprite.texture.width; } } public int Height { get { return image.sprite.texture.height; } } void Awake() { image = GetComponent<Image>(); Data = image.sprite.texture.GetPixels(); } void Update() { if (Input.GetMouseButton(0)) { Vector3 screenPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); screenPos = new Vector2(screenPos.x, screenPos.y); RaycastHit2D[] ray = Physics2D.RaycastAll(screenPos, Vector2.zero, 0.01f); for (int i = 0; i < ray.Length; i++) { if (ray.collider.tag == "Circle") { screenPos -= ray.collider.gameObject.transform.position; int x = (int)(screenPos.x * Width); int y = (int)(screenPos.y * Height) + Height; if (x > 0 && x < Width && y > 0 && y < Height) { Color color = Data[y * Width + x]; Debug.Log("clicked " + color); } break; } } } } } Found this script on forums problem is it was meant for sprite renderer and not Image. I have been trying to get the colour of the pixel from an image when i click, I have read up and found out that getpixel does not work on images, but works on rawImages but rawImages lacks the functions i need. Are any of you guys familiar with how to do this? I have been searching for a good two hours on how to go around this and haven't found anything. The script returns a null reference exception because apparently you can't use get pixel on images
Do you have "Read/Write" enabled for the texture you're trying to access? Is the texture itself marked as "Sprite"? Which line of code does the error you're getting refers to?
Does line 36 even compile? You're asking for the .collider property on an array of RaycastHit2D? Check your logs for errors... I don't think you're running the code you think you're running.
Yes, i have checked read and write and it is a sprite didn't think to read that the script stops at 22 anyways.
The whole thing (and every other script in your project) must compile successfully for any of it to run at all.