Changing texture on mouse click

Hi everybody,

I’m trying to change the texture of an object everytime I click on it with the Mouse Button.

I think it will need a sort of “var” but I can’t figure out the way to make it.

Thanks

this is what I done:


using UnityEngine;
using System.Collections;

public class interact : MonoBehaviour {
public GUIText target;

//public Texture Square;

private bool selected = false;

// Use this for initialization
void Start () {

}

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

	//renderer.material.color = Color.white;
	selected = false;
}

public void OnLookEnter(){
	//renderer.material.color = Color.red;
	target.text = "Menter code hereouse button to interact";
	
    selected = true;
}
	
void OnGUI(){
	Event e = Event.current;
	if(e.isKey && e.character == 'e' && selected){
		transform.Rotate(Vector3.up * (Time.deltaTime + 30), Space.World);
		renderer.material.color = Color.red;

		//rigidbody.AddForce(Vector3.up *100);
	}
	 
	Event q = Event.current;
	if(q.isKey && q.character == 'q' && selected){
		transform.Rotate(Vector3.up * (Time.deltaTime - 30), Space.World);
		renderer.material.color = Color.yellow;
	}
	
         var url0= "file://C:/****/Simple_Stone.jpg"; 
         var url1 = "file://C:/****/Simple_Stone_Wall.jpg"; 
             var url2 = "file://C:/****/Simple_Stone_Gate.jpg"; 

	if(Input.GetMouseButtonDown(0)&& selected){
	var bumpMap = new Texture2D(1024, 1024);
	new WWW(url1).LoadImageIntoTexture(bumpMap);
	renderer.material.SetTexture("_MainTex", bumpMap);
    }				
}	

}

You don’t need OnGUI for all that. Your Update function is resetting ‘selected’ all the time, that’s no good. I’d move all that OnGUI code to Update. Use Input.GetKeyDown(“e”)