change texture at runtime
Posted
by
user1509674
on Game Development
See other posts from Game Development
or by user1509674
Published on 2014-07-21T10:19:14Z
Indexed on
2014/08/20
16:37 UTC
Read the original article
Hit count: 144
How can I change the texture at runtime. I have done changing the label(text) at runtime. The following code is used
using UnityEngine;
using System.Collections;
public class switchtime : MonoBehaviour {
// Use this for initialization
private bool showLabel = false;
private bool showLabe2 = false;
private bool showLabe3 = false;
private bool showLabe4 = false;
public void Start() {
Invoke("ToggleLabel", 1);
Invoke("ToggleLabel2", 3);
Invoke("ToggleLabel3",6 );
Invoke("ToggleLabel4", 9);
}
public void ToggleLabel() {
showLabel = !showLabel;
}
public void ToggleLabel2() {
showLabe2 = !showLabe2;
}
public void ToggleLabel3() {
showLabe3 = !showLabe3;
}
public void ToggleLabel4() {
showLabe4 = !showLabe4;
}
public void OnGUI() {
if (showLabel) {
GUI.Label(new Rect(300, 200, 100, 20), "Copying window file..");
}
if (showLabe2) {
GUI.Label(new Rect(40, 40, 100, 20), "Epanding windows file..");
}
if (showLabe3) {
GUI.Label(new Rect(80, 80, 100, 20), "Installing Feature..");
}
if (showLabe4) {
GUI.Label(new Rect(100, 100, 100, 20), "Installing Updates");
}
}
}
Now I need to change the GUITexture at runtime. How can do this? Can anybody help me in coding?
Here is some changes I made. I worked on changing the gameObject when mouse is placed on it. This is the code I applied and its working for me
using UnityEngine;
using System.Collections;
public class change : MonoBehaviour {
// Use this for initialization
public GameObject newSprite;
private Vector3 currentSpritePosition;
void update()
{
}
void Start()
{
newSprite.renderer.enabled = false;
currentSpritePosition = transform.position;
//then make it invisible
renderer.enabled = false;
//give the new sprite the position of the latter
newSprite.transform.position = currentSpritePosition;
//then make it visible
newSprite.renderer.enabled = true;
}
void OnMouseExit(){
//just the reverse process
renderer.enabled = true;
newSprite.renderer.enabled = false;
}
}
Now the problem is that, in same code I need to set a time so that the text get loaded without the mouse click. I mean a particular time to load each text one after the another.
Here is my screen shot
Here I have placed the image one below the another,when the mouse is hovered on it it will change the text from bold to normal text.Changes process stated in (image 2,3).That code I posted is working for me.
© Game Development or respective owner