Hi all
I have created a GUIText gameobject which should be visible on an collision event.
NOTE I have created a box collider on which if an object collides I want the GUIText to turn on that is it should be visible. what should I do?
thanks you
Hi all
I have created a GUIText gameobject which should be visible on an collision event.
NOTE I have created a box collider on which if an object collides I want the GUIText to turn on that is it should be visible. what should I do?
thanks you
hi AkilaeTribe
actually I have the collision code i want too only turn on the GUIText game object i am currently using the following code
public GameObject GUItext;
void OnCollisionEnter(Collision collision){
if(collider.name ==“somecollider”){
GUIText.active = true;
}
}
NOTE: I have added this script to another collider with which i want to detect the collision and added the GUItext as a game object.
mode fat dumb chicken What is the variable collider ?
actually im new to scripting so dontno much i only want to display a text message after a collision takes place
so what should i do for the same.
Well, when a gameObject collide with something, the function OnCollisionEnter triggers, with a variable of type Collision as argument.
The collision contains some infos.
Like, the game Object being in contact.
So, you can retrieve it, by writing collision.gameObject.
You can also retrieve its name, to do some tests : collision.gameObject.name
From there, you can do plenty things.
ok so should it be like this
void OnCollisionEnter(Collisioncollision){
if(collider.gameObject.name==“somecollider”){
GUIText.active = true;
}
}
As I said, how is the word collider related to the informations given by (Collision collision) ?
can u just send me the code please
I really cant figure it out.
if(collision.gameObject.name ==“somecollider”){
Hey thanks, also now once the collision takes place I will only have to make the GUIText.Active = true; correct?
if(collision.gameObject.name ==“somecollider”){
GUIText.Active = true;
}
also this collision script should be on the collider that i want the collision to be deteactde correct the GUIText should be passed as a GameObject in that script right?
OnCollision is triggered on both objects. The content of variable collision type Collision will contain a different gameObject (the other).
http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Components.html
Hey thanks
I figured it out latter
thanks again ![]()