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 Jerry_Freeman · Jan 13, 2014 at 07:35 PM · texturelightingobjectchangeingame

How can I change an object's texture in-game when the object is unlit?

Hey, I'm so far progressing really well with Unity, the only obstacle I really find in it is the coding. Everything else seems to work well, with a few tutorials online coming in handy, of course. But I've come across a problem that I haven't seen anyone else ask, and I need some feedback as to how I can approach it.

Before you ask, no, I suck at coding, and you're going to have to babysit me through it.

But that's the thing, I don't know if coding has anything to do with this. Is there a way a sphere, which is being shined upon by a nearby light, can change it's texture, but only in a certain area, where it isn't being lit? Or is that not possible?

Thanks, in advance, for responding.

EDIT: I need to give you guys a mental picture of what I'm trying to achieve. I have a sphere, with a planet's texture, and a moon rotating around it. A light, or the sun, is shining towards it from a long distance. When the sun is not exposing the texture, and the planet is in shadow, can you change it's texture so you can see the lights of cities and such?

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 robertbu · Jan 13, 2014 at 07:41 PM 0
Share

It could and should be done with a custom shader, and no I don't know of such a shader. You might be able to hack a solution in a standard script, but it would be very expensive computationally.

2 Replies

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

Answer by sheffieldlad · Jan 13, 2014 at 07:51 PM

[EDIT] your question changed while I was writing the following.... Please see below for my new answer...]

A GameObject can't have a material. a GameObject has a renderer which has a material.

so you would do something like...

 renderer.material = myOtherMaterial;

to set the material...

The easiest way to do what you describe would be to set up zones and use the OnCollisionEnter and OnCollisionExit methods to change the spheres material. You can use primatives such as cubes or spheres to setup zones, just remove the renderer attached to them and tick the 'is Trigger' box in the colider.

Hope this helps.

The links below point to the docs.

OnCollisionExit

OnCollisionEnter

Material

Do the same as above with the zones but instead of changing the material do this...

 renderer.material.mainTexture = newTexture;

probably easier just to change the material to one which has the new texture assigned..

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 tanoshimi · Jan 13, 2014 at 07:40 PM

Are you sure you want to change materials when a light shines on an object? Why? A material defines the visual appearance of an object, including how it reflects light falling on its surface. It sounds more like you just want to define a custom shader that produces whatever visual effect you want in response to incoming light falling on the surface.

No problem if you suck at coding - try drawing a picture of what you're trying to achieve instead...

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 Jerry_Freeman · Jan 13, 2014 at 07:42 PM 0
Share

Oh god, sorry, I meant texture.

avatar image tanoshimi · Jan 13, 2014 at 07:48 PM 0
Share

Ok, well that's not so bad. You can write a custom lighting model that lerps between two textures based on the intensity of the inco$$anonymous$$g light falling on the surface - i.e. the value of _LightColor0.rgb. See here for examples of how to write a custom lighting model:

http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaderLightingExamples.html

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

create a menu to change texture on a certain object 1 Answer

Pinball playfield lighting 1 Answer

How to make something visible in lack of light in a scene? 2 Answers

Having wrong texture on my model? 1 Answer

How can I prevent lights overlapping in intensity? 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