- Home /
cant set object in prefab object, but can in the scene
hi unity i hope some1 can point me in the right direction, basicly i have an object, a snow man, when i hit the snow man i want a gui to block the screen wait a few seconds and fade out, like the squid ink in mario super karts
if i add my script to the snow man in the scene, the trigger works and the gui pops up, ( the alpha decreasing to fade out is not working)
the problem is my snowman object must be instanciated and it wont let me put my GUItexture object in to the variable GUI1 of my prefab in my project window, i have been hunting and trying for last 2 days to solve this, i am new still to coding and unity but trying my best to learn, any help in this or the alpha problem is greatly apriciated
here is my code:
var collectSound:AudioClip;
var spawnpoint: Transform;// position of spawn
var particle: GameObject;// object to spawn
var GUI1: GameObject;
var FadeNum : float = 0.12;
var displayFor : int= 3;
var alpha : float=1;
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") { AudioSource.PlayClipAtPoint(collectSound, transform.position);
Instantiate(particle, spawnpoint.position, spawnpoint.rotation);
GUI1.guiTexture.enabled = true;
yield WaitForSeconds ( displayFor);
//GUI1.guiTexture.color.a = alpha- (FadeNum* Time.deltaTime );
//if (alpha < 0.1){
GUI1.guiTexture.enabled = false;
Destroy(this.gameObject);
}
} //}
Answer by SubatomicHero · May 10, 2013 at 06:55 AM
its because GUI1 should be of type GUITexture, not a gameobject.
var GUI1 : GUITexture;
ya i tried that was also, i had the same issue wasnt able to assign it to the inspector, i have gotten around the problem by making the trigger on the player, thus having the object in the scene, and no longer needing to assign the variable on the not yet Instantiated prefab
cheers for the help though it is very much appreciated,
Your answer
Follow this Question
Related Questions
Drawing Sector around GameObject in GameView: GUITexture or 3D Object 1 Answer
Reinitialize prefab 0 Answers
Scripts/buttons getting old (prefab?) values of variables 1 Answer
2D Tilemap Gameobject Brush Script for Editor 0 Answers
How many variables can i have of type 'Prefab' in a scene at one time? 1 Answer