• 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 eradiuslore · Oct 11, 2011 at 08:43 PM · mousetexture2dpixelgetpixel

getPixel co-ordinates not screen co-ordinates based on mouse position

Hi, im trying to get the x,y co-ordinates of a pixel to use in the GetPixel function. I have tried using a raycast to get the hit position based on Camera.main.WorldToScrenPoint however this gives a screen co-ordinate, not a pixel co-ordinate on the readable texture. So how do you do it, by that i mean get pixel co-ordinates off a specific texture in the scene when the mouse is over it.

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
3

Answer by aldonaletto · Oct 11, 2011 at 08:52 PM

You should use the Raycast, but from the RaycastHit structure returned, get textureCoord: it's the UV coordinates of the pixel hit. The docs give in the link above an example of how to set the pixel hit - it's probably easy to adapt to your case.

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
2

Answer by DaveA · Oct 11, 2011 at 08:51 PM

http://unity3d.com/support/documentation/ScriptReference/RaycastHit.html check out textureCoord

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 eradiuslore · Oct 11, 2011 at 11:00 PM 0
Share

hi thanks thats very helpful :)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

create readable colour map 1 Answer

Steps in Texture2D after writing values to an array 1 Answer

Mouse click on a box 0 Answers

How to fill texture that would be avaliable to ither shaders? 1 Answer

Getting color from RayCastHit: Able to retrieve texture coordinates but Texture2D still shows as "degenerate" (0x0) 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges