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 phavington · Aug 01, 2012 at 09:05 PM · animationplayerpickupreadbook

How to make player have the ability to pickup and read a book (like in Skyrim)

I want my player to be able to pickup a book that i make on the ground, and give them the ability to read it, like in skyrim. I have an idea on how to do it with an animation, but im not sure how to pause the game in the background and apply the animation.

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

5 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by agamedesigner · Aug 03, 2012 at 03:22 AM

Sure you can do that. There are a lot of different ways.

Here is just a simple way.

This will cast a ray from where the mouse cursor is, and if the ray hits something tagged as "Touchable" then it will take the appropriate action.

 public class TryTouch : MonoBehaviour
 {
 
  GameObject currentlyTouched;
 
  void Touch()
  {
  Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  RaycastHit hit;
 
  if (Physics.Raycast (ray, out hit, 10f))
  {
 
  if(hit.collider.gameObject.tag == "Touchable") // Did it hit the paper?
  {
  // Show the paper
  hit.collider.gameObject.SendMessage("OnTouch");
  currentlyTouched = hit.collider.gameObject;
  }
  }
  }
 
  void Update()
  {
  if(Input.GetMouseButtonDown(0)) // If the player clicks with the left mouse button
  {
  if(currentlyTouched == null)
  {
  Touch(); // then execute Touch()
  }
  else
  {
  currentlyTouched.SendMessage("UnTouch");
  currentlyTouched = null;
  } 
  }
  }
 }

As far as actually showing the paper, there are lots of things you can do. In this simple case, the above script can be attached to an empty GameObject. The below script is attached to the actual in-game Paper model that you want the person to be able to read. Make sure that the GameObject for your paper has a collider, and set the GameObject's tag to "Touchable" (you'll have to add a new tag).

Once that is done, you want to attach the script below to the paper. Then create a new GUITexture and set it up with your paper image from photoshop. Make it a child of your paper model that will be clickable, and disable it. Then drag it into the displayImage slot of the script on your paper model.

You can of course add functionality so that you can flip through pages who are children of the 3d paper model. But I think I have set out enough of a foundation for you to figure that out.

 public class TouchableObject : MonoBehaviour
 {
  public GameObject displayImage;
 
  void OnTouch()
  {
  displayImage.SetActiveRecursively(true);
  }
 
  void UnTouch()
  {
  displayImage.SetActiveRecursively(false);
  }
 }
Comment
Add comment · Show 14 · 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 agamedesigner · Aug 03, 2012 at 03:38 AM 0
Share

sorry for the indentation; can't get it to look proper.

avatar image phavington · Aug 03, 2012 at 04:25 AM 0
Share

Thank you so much for your responds (really infomative), but I am getting a whole bunch of errors:

Assets/Scripts/papertouchablefunction.js(1,30): BCE0043: Unexpected token: :.

Assets/Scripts/papertouchablefunction.js(2,1): BCE0043: Unexpected token: {.

Assets/Scripts/papertouchablefunction.js(3,9): BCE0043: Unexpected token: GUITexture.

Assets/Scripts/papertouchablefunction.js(14,1): BCE0044: expecting EOF, found '}'.

Assets/Scripts/playertouchablefunction.js(1,23): BCE0043: Unexpected token: :.

Assets/Scripts/playertouchablefunction.js(4,12): UCE0001: ';' expected. Insert a semicolon at the end.

Assets/Scripts/playertouchablefunction.js(8,5): UCE0001: ';' expected. Insert a semicolon at the end.

Assets/Scripts/playertouchablefunction.js(9,12): UCE0001: ';' expected. Insert a semicolon at the end.

Assets/Scripts/playertouchablefunction.js(11,32): BCE0044: expecting ), found 'hit'.

Assets/Scripts/playertouchablefunction.js(11,35): BCE0044: expecting ), found ','.

Assets/Scripts/playertouchablefunction.js(11,37): BCE0043: Unexpected token: 10f.

Assets/Scripts/playertouchablefunction.js(14,2): BCE0043: Unexpected token: if.

Assets/Scripts/playertouchablefunction.js(14,48): UCE0001: ';' expected. Insert a semicolon at the end.

Assets/Scripts/playertouchablefunction.js(17,48): BCE0044: expecting :, found ';'.

avatar image Radon · Aug 03, 2012 at 04:27 AM 0
Share

Just to clear something, this is C# not javascript

avatar image phavington · Aug 03, 2012 at 04:36 AM 0
Share

Woops, sorry.. I'm still getting these errors though:

Assets/Scripts/papertouchable.cs(10,15): error CS1061: Type UnityEngine.GUITexture' does not contain a definition for SetActiveRecursively' and no extension method SetActiveRecursively' of type UnityEngine.GUITexture' could be found (are you missing a using directive or an assembly reference?)

Assets/Scripts/papertouchable.cs(15,15): error CS1061: Type UnityEngine.GUITexture' does not contain a definition for SetActiveRecursively' and no extension method SetActiveRecursively' of type UnityEngine.GUITexture' could be found (are you missing a using directive or an assembly reference?)

avatar image agamedesigner · Aug 03, 2012 at 09:22 AM 0
Share

Sorry, it was pretty late when i posted that ;)

I had actually fixed that line.. not quite sure how it reverted.. but anyway, in TouchableObject.cs:

change this:

 public GUITexture displayImage;

to this:

 public GameObject displayImage;

I went ahead and changed it in the original post above as well.

Show more comments
avatar image
1

Answer by Radon · Aug 02, 2012 at 05:03 AM

As DNP said. Create a GUI Text and apply the myGUIText.enabled = false; to it. Then create and make if(Input. GetButtonDown("Y")) then myGUIText.enabled = true;. MyGuiText as in your gui text name.

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 phavington · Aug 03, 2012 at 02:33 AM 0
Share

Well, I have the papers that I want to appear already done in Photoshop (I decided to go with a piece of paper ins$$anonymous$$d of a book). Is there a way to have the player click on the paper and then have the paper appear on their screen so they can read it?

avatar image
1

Answer by Loius · Aug 03, 2012 at 02:57 AM

For pausing, one method is to set Time.timeScale to 0.0001 while the game is "paused" and the animation is playing. Play the animation at 10,000 times normal speed (because 10000 * 0.0001 = normal speed). While there's nothing playing that relies on time, set timeScale to zero (so nothing moves if players pause for days at a time). Then when you unpause set timeScale back to 1.0.

Comment
Add comment · 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
0

Answer by DNP · Aug 02, 2012 at 04:31 AM

I personally havent played skyrim. But what you could do is make a GUITexture Appear once you click on the book, and the have it disappear when you click again.

Comment
Add comment · 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
-1

Answer by Radon · Aug 03, 2012 at 02:52 AM

Create a cubes and drag each of your papers (photos into those cubes or change the render image). Resize your cube so it fits your cube cover. Make your cubes children of your main camera and set it in front of the camera. Set theme all deactivated when the scene starts so you can't see anything. Then apply each by the following code

 var First: GameObject;
 var Second: GameObject;
 var Third : GameObject;
 
 
     function Start () 
     {
      First.SetActiveRecursively(false);
      Second.SetActiveRecursively(false);
      Third.SetActiveRecursively(false);
     }
 
     function Update () 
     {
      if(Input.GetKeyDown("1")){
      First.SetActiveRecursively(true);
      Second.SetActiveRecursively(false);
      Third.SetActiveRecursively(false);
      }
 
      if(Input.GetKeyDown("2" )){
      First.SetActiveRecursively(false);
      Second.SetActiveRecursively(true);
      Third.SetActiveRecursively(false);
      }
 
 
 
      if(Input.GetKeyDown("3" )){
      First.SetActiveRecursively(false);
      Second.SetActiveRecursively(false);
      Third.SetActiveRecursively(true);
      }
 
 }
Comment
Add comment · Show 2 · 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 phavington · Aug 03, 2012 at 03:17 AM 0
Share

Thank you so much! Is there a way I can use this so if I click on an object in the game, this appears? Ins$$anonymous$$d of pressing a button?

avatar image Radon · Aug 03, 2012 at 03:22 AM 0
Share

Please make a different topic and I will surely help you. I'm always glad to help unity users.

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

11 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

Related Questions

Player Animation change when pickup Weapon 0 Answers

Trail of color behind the player 2D c# 1 Answer

Idle Animations, Player Walking 0 Answers

Create Player From Values [ Photon ] 0 Answers

How to move player after animation 2 Answers


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