Why is this giving me a error?

This is the script:

All I want to do instantiate the object texture, and then have a reference to its sprite renderer.
public Transform texture;

public Transform texture;

void CreateGrid(/*int w, int h, int[] info, Vector2 offset*/){
GameObject refer = Instantiate(texture, Vector3.zero, Quaternion.identity, transform) as
GameObject;         
SpriteRenderer sprite = refer.GetComponent<SpriteRenderer>();
}

2844453--207672--upload_2016-11-7_18-20-9.png

I think texture needs to be a GameObject not a Transform.

texture is a transform but you’re trying to cast the instantiated copy of it as a GameObject. “as casts” return null if the cast fails - which it is in this case.

Thanks!

So at the end what I did was this:

sprite = ((Transform)Instantiate(texture, pos, Quaternion.identity, transform)).GetComponent<SpriteRenderer>();