x


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.

more ▼

asked Aug 03, 2010 at 09:22 AM

remvan3d gravatar image

remvan3d
49 22 16 22

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Aug 03, 2010 at 11:31 AM

Wolfram gravatar image

Wolfram
10.6k 20 30 74

I don't even know what comands resets a function. :S Am still REALLY wet behind the ears when it comes to scripting.

Aug 03, 2010 at 12:02 PM remvan3d
  • 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.

Aug 04, 2010 at 04:11 PM Wolfram
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4661
x1646
x753
x263
x215

asked: Aug 03, 2010 at 09:22 AM

Seen: 1712 times

Last Updated: Aug 03, 2010 at 09:22 AM