- Home /
Pick up paper view as gui
hey guys, anyone have any ideas on how to mouseclick on a paper(object) using raycast, Then view it as an GUI I am guessing? Putting it back would be nice too, I guess that would be something like when you click the mouse again the gui stops until you click on the object again. Welcome all answers lol
Answer by Glacier Games · Feb 18, 2014 at 03:35 AM
Your method would depend on how you want it to look. 1: when you click on the paper, a zoomed in version would show up square to the camera. This is what you generally see in most video games. This is Skyrim's technique
var showPaper : boolean;
var cameraPaper : GameObject; //in the editor, you would have to create a piece of paper that is always square to the camera. In this script, it will be enabled and disabled so that it is only seen when you want it to be.
function Update(){
//every frame, ask for a left click
if(Input.GetMouseButtonDown(0)){
//if the cameraPaper is showing, then hide it
if(showPaper){
showPaper=false;
}
else{
//I'm guessing that you want to ask for a click when the camera is looking directly at the real paper
//the real paper must have a collider on it as well. It can be a trigger if you want.
//if the player clicks on the real paper, then show the cameraPaper
var hit : RaycastHit;
if(Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, hit, 10/*this is the distance*/)){
if(hit.transform.name=="paper"){
showPaper = true;
}
}
}
}
cameraPaper.active = showPaper;
}
2: when you click on the paper, the paper disappears and you get the new zoomed in version square to the camera To do this, it is the same thing as the last one, except you would want to hide and show the real paper as well.
3: when you click on the paper, it moves towards the camera as if someone was picking it up, and positions itself to be facing the camera. I rarely see this in video games. but it would require Lerping to and from a set position for reading.
Hey! thanks for the script! I applied the script to the real paper and I have the hidden paper applied to the maincamera. Is that right?
when I click on the paper it doesn't show, but if I toggle the show paper in the inspector it does indeed show up on the main camera
is the script suppose to be applied to the paper yes?
You should actually apply it to another object, probably the camera or your player. I usually have a Empty object i call "GUI" where i put all of my gui scripts.
And do you have a collider attached to the real paper? and is the real paper's name "paper"? both of these are necessary for this script to work. however, this script is just a starting point and you should probably modify it slightly to fit with your game. For example, this script asks for the name of the object that was clicked on, but it may or may not be better for you to ask for the tag or layer or something.
Oh, and I'm using the same technique as Bethesda's Skyrim. I don't know if you've ever played, but the mouse is always in the center of the screen in Skyrim. In other words, the focus is on whatever the player is directly looking at. You might need to change this as well if you have a mouse that moves around the screen in-game. Cheers!
yea... strange won't work for me, I even have a new scene made now for testing, I can screenshot if you want? I can :) But I have a paper named paper I made an empty, applied the script to it. I have camPaper object attached to the maincamera in view I dragged the camPaper into the script where it should go
But when I click the real paper it doesnt enable. But it will in the inspector... weriddddd lol
If you have a moving cursor in-game, then change
Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, hit, 10/*this is the distance*/)
to
Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit, 10/*this is the distance*/)
Not working:( Do you have it working yourself? I really can't understand whats wrong, it's the clicking part it seems
$$anonymous$$y cursor is static in the middle of the screne in my real game But i just tested this with the standard fps and still nothing hmmmm
Your answer
Follow this Question
Related Questions
Arial camera get selected point 2 Answers
How can I add a distance cap to this script? 3 Answers
Problem with GUI Buttons with WorldSpace Canvas 2 Answers
Disabling Raycast with GUI 0 Answers
GUI Click and Hide 1 Answer