Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ouija · Feb 18, 2014 at 02:30 AM · guiraycastmouseclick

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ouija · Feb 18, 2014 at 05:15 AM 0
Share

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?

avatar image Glacier Games · Feb 18, 2014 at 05:25 AM 0
Share

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!

avatar image Ouija · Feb 18, 2014 at 05:34 AM 0
Share

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

avatar image Glacier Games · Feb 18, 2014 at 05:34 AM 0
Share

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*/)
avatar image Ouija · Feb 18, 2014 at 05:41 AM 0
Share

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

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges