-1

I'm trying to learn how to use the GetPixels function and I'm trying something simple for now - to get the pixels of the current object of a 2 x 2 area. I just want to display the results in the console first so I can better understand the results of GetPixels.

public class timecode : MonoBehaviour {

Color[] pixColors = GetPixels(0, 0, 2, 2);

// Use this for initialization
void Start () {

    Debug.Log(pixColors [0]);
}


// Update is called once per frame
void Update () {
}
}

I'm getting "The name `GetPixels' does not exist in the current context"

KeepCool
  • 497
  • 1
  • 6
  • 24
  • 1
    `GetPixels` is a member function of `Texture2D`. So, you need an Texture2D instance to examine pixels. – align Mar 23 '17 at 18:42

1 Answers1

2

You need a Texture2D to access the GetPixels Method, try to add a public Texture2D Variable, assign a texture to it in the unity inspector, and then Get the Pixels with yourTextureVariable.GetPixels(...).

Take a look at the documentation: https://docs.unity3d.com/ScriptReference/Texture2D.GetPixels.html