- Home /
Reset GUI texture after respawn
I have this GUI texture that changes depending on how many times the jump button i pressed during midair, but when I respawn the function does not work again. It it does not reset, and it stays on the last GUItexture image from the previous jump.
This is my GUI script:
var trick6 : Texture2D;
var trick5 : Texture2D; var trick4 : Texture2D; var trick3 : Texture2D; var trick2 : Texture2D; var trick1 : Texture2D;
static var SPLASH = 6;
function Update () { switch(SPLASH) { case 0: guiTexture.texture = trick1; break;
case 1:
guiTexture.texture = trick2;
break;
case 2:
guiTexture.texture = trick3;
break;
case 3:
guiTexture.texture = trick4;
break;
case 4:
guiTexture.texture = trick5;
break;
case 5:
guiTexture.texture = trick6;
break;
}
}
I trigger it though my character controller script in the jump function here (post onlye the jumping part of the script):
//Jumping
var jumpSpeed = 15.0; var gravity = 20.0; var speedSmoothing = 5.0; var maxFallSpeed = 50.0;
private var moveDirection = Vector3.zero; private var grounded : boolean = false; private var jumpCount:int; private var onGround:boolean;
function FixedUpdate() { if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
jumpCount = 0;
} if (Input.GetButtonDown ("Jump") && jumpCount < 20) { moveDirection.y = jumpSpeed; jumpCount++; SplashScript.SPLASH -= 1;
}
The third last line "SplashScript.SPLASH -= 1:" is where i trigger it through my character controller script.
Answer by Wolfram · Aug 03, 2010 at 11:31 AM
In your script, you constantly subtract -1 from SplashScript.SPLASH, but never reset it. You probably want to reset it to 6 in the "if(grounded)" case. Also note that your SplashScript does nothing for that default value - you probably want to add a "case 6", which resets to the inital texture.
I don't even know what comands resets a function. :S Am still REALLY wet behind the ears when it comes to scripting.
use "var trickDefault : Texture2D;" and assign your initial texture (the one when you don't jump) to it.
add this case to the switch: "case 6: guiTexture.texture = trickDefault; break;"
add this line directly after "jumpCount = 0;": "SplashScript.SPLASH = 6;"
Note that with your method (since you start with 6 and subtract when jumping) trick6 is the texture shown after 1 jump, trick5 after 2 jumps, etc.
Your answer
![](https://koobas.hobune.stream/wayback/20220613070325im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trigger respawn after collision? 3 Answers
How do I make a character die when he fells. 1 Answer
Detect with Object has been triggered 3 Answers
Car won't return to respawn point after hitting a trigger 2 Answers
Counting with GUI Textures 1 Answer