- Home /
Question by
jamie · Jan 29, 2011 at 07:54 AM ·
collisionguiguitextureenable
Enable a GUI texture after player collides with another object
So I've got the object colliding part done but I don't know how to enable a GUI texture after the collision.
Any ideas?
Cheers.
P.S. Using J script.
Comment
I'm trying to do something similar but don't have the colliding part yet. How have you done this?
Answer by Mike 3 · Jan 29, 2011 at 10:22 AM
Assuming your GUITexture is not on the scripted object, but somewhere else, and you don't mind dragging it onto the public variable of the script in the inspector, something like this should work:
var tex : GUITexture;
function OnCollisionEnter(collision : Collision) { //your code tex.enabled = true; }
Answer by Ngo · Sep 19, 2013 at 07:31 AM
I have same problem, and I discover this way is also fine
var showHPBar:GUITexture;
var MaxHP:int = 1000;
var HP:int = 500;
function Update(){
showHP();
}
function showHP(){
if(MaxHP != HP){
showHPBar.gameObject.SetActive(true);
}
}