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 chuck3r · Jul 22, 2014 at 03:16 AM · raycasthit

Raycasthit.textureCoord not painting colored pixels

I'm a beginner to Unity and have been fiddling around with it for the last few days. The end goal for me is to create a clickable world map as described here. The instructions on that page is what led me to initially try using Raycasthit.textureCoord to paint a the clicked portion of my map a certain color.

Right now, I'm just using a 5x3x1 cube with a plain white texture attached to it. As mentioned in the documentation, I've attached a mesh collider to the cube. Also, the script with the Raycasthit.textureCoord code is attached to the camera as instructed (it is copy + pasted from the documentation). I understand for the most part what the code means, (after reading into all the variables and types), but I don't seem to understand why it's not doing what it's supposed to do (no console errors in sight).

Any help or direction would be appreciated!

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
0

Answer by robertbu · Jul 22, 2014 at 03:20 AM

I just tested the script in the reference. I found it had a couple of problems to be fixed before it would run, but it ran and worked. Note it is likely this script will make permanent changes to the texture. I use a Quad with Unlit/Texture shader and set the texture to something bright.

As for your goal, I've used similar code and it works well. The only caution is don't try and match colors exactly. Allow some leeway when detecting colors and mapping them.

Comment
Add comment · Show 7 · 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 chuck3r · Jul 22, 2014 at 03:30 AM 0
Share

What were the problems you had to fix before it worked? And what do you mean by Quad?

Thanks for the help/advice!

avatar image robertbu · Jul 22, 2014 at 03:47 AM 0
Share

Line 18 got changed to this:

  Texture2D tex = renderer.material.mainTexture as Texture2D;

Line 22 got changes to this:

  tex.SetPixel($$anonymous$$athf.RoundToInt(pixelUV.x), $$anonymous$$athf.RoundToInt(pixelUV.y), Color.black);

Note with the second change, I could have just cast the values to integers. Actually I'm not sure why it did not automatically convert the floats to ints.

If you do Game Object > Create Other > Quad you get a Quad. A Quad is a 1 x 1, two triangle plane that is oriented vertically.

avatar image chuck3r · Jul 22, 2014 at 04:13 AM 0
Share

Very strange. I made the changes but the console keeps telling me to put a semicolon at the end of the Line 18 code you proposed. And I definitely have one there.

This is the error: "Assets/raycast.js(25,22): UCE0001: ';' expected. Insert a semicolon at the end."

Also, if you don't $$anonymous$$d, what's the logic behind the changes you proposed?

Thanks again.

avatar image robertbu · Jul 22, 2014 at 04:23 AM 0
Share

Ahhh, you are using Javascript. I just tested the Javascript version of this script, and it ran without changes and worked for me. The changes I outlined were in the C# version of the script. Either they did a poor job of translating from Javascript to C#, or more likely something in Unity changed to require the script changes in the C# version, and the reference did not keep up.

avatar image chuck3r · Jul 22, 2014 at 05:02 AM 0
Share

Oops! Sorry I didn't notice earlier, new with Javascript syntax myself.

After reverting back to Javascript, I'm getting this as a cautionary warning from the console:

"Assets/raycast.js(25,53): BCW0028: WARNING: Implicit downcast from 'UnityEngine.Texture' to 'UnityEngine.Texture2D'."

(Referring to Line 18 code)

Could that possibly have something to do with it?

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

2 People are following this question.

avatar image avatar image

Related Questions

Null Reference Exception issue getting the tag of an object hit by Raycast 2 Answers

How to Instantiate a line or a ray that goes through all colliders and send a message to them???? 1 Answer

Player Attacking Enemy Issue 0 Answers

Trouble with rigidbody.AddForce 0 Answers

Raycast problems! 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