x


Find 2D Texture via Script to use in Static Function

Alright here is what i am trying to do. I have a health script so that when i get shot it displays a hint (much like the one in 'Red Dead Redemption') saying get to cover. The hint is a GUIText object, which is rendered over a GUITexture background. I want it so that when i want to display the hint, the texture fades in and out instead of just popping in and out as it looks odd, and unfinished. So my solution was to make a script which is NOT attached to the GUITexture (for varies reasons) and i want to have it separate from my hint script as i will have more hints (meaning more scripts) then JUST getting shot, and i want it universal. So my idea was this:

static function FadeOut () {
    var HintsBackground = GameObject.Find("HintBackground");
    while (HintsBackground.color.a > .1) {
        HintsBackground.color.a -= Time.deltaTime;
    }
}

The problem is since the function has to be static if i want to call it, i cant simply use: var HintsBackground : GUITexture. So my solution was GameObject.Find...problem is 'color' is NOT a member of GameObject. So what i am asking is, how can i either, change GameObject to GUITexture, or what is the best way to call a GUITexture. Thank you for you time.

more ▼

asked Jul 04 '10 at 03:46 AM

xToxicInferno gravatar image

xToxicInferno
485 24 28 41

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

2 answers: sort voted first
var HintsBackground = GameObject.Find("HintBackground");
var background = HintsBackground.GetComponent( "GUITexture" );
// adjust background color here
more ▼

answered Jul 04 '10 at 04:01 AM

Tetrad gravatar image

Tetrad
7.2k 27 37 89

Works perfectly! Thank you for such a quick response!

Jul 04 '10 at 04:10 AM xToxicInferno

We posted the same thing, my code was shorter, and I posted it first, yet you get the accept... man... this community is so backwards sometimes it's unbelievable...

Jul 04 '10 at 09:29 AM qJake
(comments are locked)
10|3000 characters needed characters left

I think you want HintsBackground.guiTexture.color

more ▼

answered Jul 04 '10 at 03:59 AM

qJake gravatar image

qJake
11.6k 43 78 161

(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:

x2087
x478
x475
x276
x207

asked: Jul 04 '10 at 03:46 AM

Seen: 1834 times

Last Updated: Jul 04 '10 at 03:46 AM