- Home /
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.
Answer by Tetrad · Jul 04, 2010 at 04:01 AM
var HintsBackground = GameObject.Find("HintBackground");
var background = HintsBackground.GetComponent( "GUITexture" );
// adjust background color here
Works perfectly! Thank you for such a quick response!
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...
Your answer
Follow this Question
Related Questions
Function to locate game object with smaller distance to target makes the game lag - UnityScript 1 Answer
Finding the angle between two GameObjects 1 Answer
Loading function into array using GameObject.Find 1 Answer
Attaching GameObject and ParticleSystem to C# script 1 Answer
Alternatives to GameObject.Find(); 1 Answer