Hello,
i’m trying to load and apply a simple texture on my plane. I’m using C#.
Texture2D p = new Texture2D(10, 10);
p = Resources.Load("Grass", typeof(Texture2D)) as Texture2D;
Debug.Log(p);
mGfxGameGrid.renderer.material.mainTexture = p;
But dosen’t work. So anyone can explain me the way to load a texture (or material) and assign Its to my plane? I’m sorry for this noob question, but i can’t understand how can i solve it from the documentation.
I’ve tried to use “glass” but it still don’t work… Now i will show you my entire class:
using UnityEngine;
using System.Collections;
/*
Classe che si occupa solo della gestione grafica
*/
public class GfxGameGrid
{
/*
Class Members
*/
private GameObject mGfxGameGrid; /* La Gfx della Matrice */
private Vector3 mGfxGameGridPosition; /* La posizione della Matrice */
private Vector3 mGfxGameGridScale; /* La grandezza della Matrice */
/*
Class Methods
*/
public void initGfxGameGrid(Vector3 position, Vector3 scale)
{
Debug.Log("Creating GamePlane..");
mGfxGameGridPosition = position;
mGfxGameGridScale = scale;
mGfxGameGrid = GameObject.CreatePrimitive(PrimitiveType.Plane);
mGfxGameGrid.transform.position = mGfxGameGridPosition;
mGfxGameGrid.transform.localScale = mGfxGameGridScale;
//Texture t = new Texture();
//mGfxGameGrid.renderer.material.SetTexture("Diffuse", t);
Texture2D p = new Texture2D(10, 10);
p = Resources.Load("glass", typeof(Texture2D)) as Texture2D;
Debug.Log(p);
mGfxGameGrid.renderer.material.mainTexture = p;
Debug.Log("Created GamePlane");
}
}