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 135Aidreanflask · Aug 04, 2014 at 08:21 PM · beginnerconfused

how to pick up and read paper [solution found sorry]

im a BEGINNER in unity and i want to have my player pick up and read a piece of paper but i don't know how to script it so that way you can see the paper on the ground pick it up and it pops up on the screen with written text on it... can someone help me?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by drex150 · Aug 04, 2014 at 08:59 PM

There is a lot you want to happen with this and there's a lot of things you need to do to make it happen.

I'm going to give you a brief rundown of how you'd go about doing it, but I'm not gunna write the code for you because it would be rather large. Instead I'll point you in the right direction.

So first off, you're going to want to place your paper in the scene with your player. You'll want the paper to have a tag associated with it. (http://docs.unity3d.com/Manual/Tags.html)

In order for the player to interact with the paper, you're going to need to use Raycasting that is set to the camera. (http://docs.unity3d.com/ScriptReference/Physics.Raycast.html)

Once the ray touches the paper, sees the tag of the paper says "Paper", and the player is close enough to the paper (distance is automatically calculated in raycasting) you will need to press a button. (http://docs.unity3d.com/ScriptReference/Input.GetButtonDown.html) The button you press will depend on the inputs you set up. To access the inputs go to Edit > Project Settings > Input. (http://docs.unity3d.com/Manual/class-InputManager.html)

Once the button is pressed, if you want the paper to disappear, you need to destroy it. (http://unity3d.com/learn/tutorials/modules/beginner/scripting/destroy) If you want it to stay, you can skip this step.

Now you need to make the object appear in front of the camera. There's lots of ways to go about this. You can move the paper that you just pressed the button on, or you can delete that object and instantiate a new one in front of the camera, or you can use a GUI texture and just enable it when you click that paper. There's probably a lot of other ways to get the same effect too. You'll have to figure out what works best for you.

Now you'd just need to press another button when you are finished looking at the paper to make it go away.

That's the way I'd probably do it myself. So I hope it helps at least get you started.

Comment
Add comment · Show 1 · 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 AW0610AUT · Aug 04, 2014 at 09:13 PM 0
Share

dang. sorry ninjad me.

avatar image
2

Answer by AW0610AUT · Aug 04, 2014 at 09:12 PM

If you are a complete beginner it might be better to lern the basics first. But i would (depending on the situation 2d/3d..) make something like this:

  private var Player: GameObject;
  private var distance: float;
  private var open: boolean = false;
  privat var someDistance: 10; //this is the max. distance you  can be away from the Paper and still read it:
     
     function Update(){
     
     Player = gameObject.FindWithTag ("Player"); // here you find the player in the scene (make sure the player is tagged as "Player")
     
     distance = Vector3.Distance(transform.position,  Player.transform.position); // with Vector3.Distance you can get the distance between two positions.(The Vector length)
     if (distance < someDistance){ //you check if you are not to far away
     open = true; //if you are close enough to read it open will be set to true
     }
     else
     open = false;
     }
     
     function OnGUI () { //in the gui you check if open = true and display the message you want to display
     if (open){
     GUI.Label (Rect (0,0,Screen.width,Screen.height),"This is a Note")
     
     }
     }
     }

I held it somewhat basic and explained a little bit. (Note im not the best programer out there). Not tested by the way. But again you lern more when you try stuff yourself.

Here are some Links you should check out: http://docs.unity3d.com/ScriptReference/Vector3.Distance.html http://docs.unity3d.com/ScriptReference/GUI.Label.html http://unity3d.com/learn/tutorials/modules/beginner/scripting/variables-and-functions

Comment
Add comment · Show 1 · 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 drex150 · Aug 05, 2014 at 01:35 AM 0
Share

Haha, no worries. Your answer is really helpful too! The only reason I didn't decide to go the same route was because your code doesn't care if the player is facing the paper. Ins$$anonymous$$d he just has to be close by. I was going more for, you must be looking at the paper in order to interact with it hehe.

Your way is definitely easier though, which is good for a beginner! ^^

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Left Click to Play Audio Help? 0 Answers

Where can I find tutorials for scripting in c#?? 1 Answer

How do I deselect an object when another is selected? 2 Answers

How do I deselect an object when another is selected? 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