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 AnikeArmen · Nov 25, 2014 at 08:38 AM · javascriptguitexturecrosshairhoversubtitle

Press "E" to activate Object. Display Gui-texture or Text ??

I'm currently a high school student working on an animation/game development project, and me and my group partners are having trouble figuring out how to get what we had envisioned to work.

Our goal was to have the cursor to be hidden in our scene, and instead have a crosshair to be at the center of the screen. When the crosshair hovers over certain objects when the player moves the mouse around, we want the object's texture to change a color so the player knows its "selectable". Upon hover, a text would display in the bottom of the screen to tell the player they can press "E" to activate the object. Upon pressing "E" to activate the object, it would either display subtitles/text at the bottom center, or a guitexture/image onto the screen. (E.g. if you pressed E on a paper on a desk, an overlay of that paper would be plastered across the players screen so it can be read legibly vs seeing it from afar)

Our objects are made in Maya and imported into Unity. We are working in javascript.

We are clearly rookies, but any code or direction would be greatly appreciated. Our project is due this Wednesday afternoon, and this is the only thing left in our project that we haven't completed.

Comment
Add comment · Show 1
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 HarshadK · Nov 25, 2014 at 08:01 AM 0
Share

The method is something as:

  1. Use Raycast to shoot a ray from your crosshair.

  2. If it hits an object then change the texture of that object using $$anonymous$$aterial.SetTexture().

  3. Also store the current texture of the object so that when it is not selected you can make that object have his original texture back.

  4. When raycast hits an object check if it is the same object as previous before replacing texture. If not same give previous object its original texture back.

  5. Also on raycast show the text to press $$anonymous$$

  6. If an object is hit and user presses E key then perform the action to pick up that object.

Here Raycast and SetTexture are the key things. Rest is just plain logic. There are a lot of cases not covered in this logic above which you can as per your need. :-)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by JNaski · Nov 25, 2014 at 09:48 AM

I have made something similar. You want to use Raycast and check if it hits an object.

 if(Physics.Raycast (transform.position, transform.forward, hit, 5))

This is the basic check for Raycast.

Then you can for example use switch case to check what tag the object has. Then when proper key is pressed something happens.

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 Ellis · Nov 25, 2014 at 10:44 AM

In order to hide your cursor you type "Screen.showCursor = false". In order to know what you are looking at you'll want to use raycast as those above me has already pointed out. For the text or images to pop up you could look at the GUI and for the crosshair to change color you want to look after either a color change or a way to switch between different materials.

Here are a few links that might get you starting:

Raycast

Raycast

Change Color

GUI

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

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

Make crosshairs disappear while aiming 0 Answers

Fade multiple GuiTextures in ONE Javascript 1 Answer

Removing crosshair on save 1 Answer

Shooting with a locked camera position 1 Answer

Disable player input whilst a GuiTexture is enabled? 0 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