- Home /
Showing a picture on collision errors
Hi! I am trying to make it so that when I touch a game object, it will display a picture, and then when you stop touching it the picture will disappear. I have tried looking through others answers, but I am getting errors with their scripts. I tried looking through the show gui on collision and show 2D texture on collision but I can't figure out how to get them working. I am a complete beginner when it comes to scripting so if anyone could please explain it to me it would be GREATLY appreciated. Thanks so much for any help!
Are you having trouble detecting clicks, showing pictures, or both?
I'm honestly not even sure which script to use. Would a script to display a gui work or is there a specific way to display a 2d texture when you click an object?
Answer by MD_Reptile · May 17, 2013 at 02:08 PM
so all you need is for a picture to cover the whole view of the screen when a collision happens to a certain object?
well, you could place a plane which covers the view entirely, blocking all other objects, and simply turn on the renderer when the collision happens. You would want to apply the texture of your image to the plane.
(in C#):
void OnCollisionEnter(Collider other)
{
if(other.gameObject == TargetGameObject) // set this as public var in inspector, place the object you want to trigger there
{
// first position the object in the editor, if you move your camera make it a child of the camera
other.gameObject.renderer.enabled = true; // then make sure you disable the renderer (checkbox) so that you cant see it until the trigger happens
}
}
or your could try GUITexture, and do something similar but instead of enabled renderer, enable the guitexture.
Or maybe im wrong, you need it so that a mouse click triggers the picture?
if it can be a mouse click anywhere, the just check for a mouse click and enable the renderer (this would be in update() method):
if(Input.GetKeyDown(KeyCode.Mouse0))
MyPlaneObject.renderer.enabled = true;
and assign myplaneobject as the plane.
buttt if it has to be a mouseclick only on an object, its often easier to just raycast from your mouse position (when you click) and if it hits the object, then trigger the method, but this gets to be more project specific, and I cant really give a solid example offhand
Thanks for your detailed response! Yes sorry I made a mistake I want it to be on mouse click not the player collision. And it would be clicking a specific object. Since you can't give a solid example do you know of a good tutorial that would $$anonymous$$ch me how to do this? THanks for your time :)
@axillarhd When I first started with unity I really learned a lot from 3dbuzz (google em) - they have some good examples for learning many of these sorts if things.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Block Collision Sliding off 0 Answers
Collision destroy help. 1 Answer
Tags not working? 1 Answer
Show enemy health on collision help. 3 Answers