Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by PaxStyle · Mar 23, 2014 at 07:37 PM · shadowsshadowdisable

Disable shadows

Hi guys, I would like disable shadows when a button is pressed, i did this, but for my case, don't work. How can I disable shadows? Thank you in advance.

 var buttonstyle : GUISkin ;
  
 function Start () {
  
 }
  
 function OnGUI (){
  
 GUI.skin  = buttonstyle;
 if(GUI.Button(new Rect(100,200,200,70),"")){
  
 renderer.castShadows = false;
  
 }
  
 }
Comment
Add comment · Show 3
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 getyour411 · Mar 23, 2014 at 09:49 PM 0
Share

This should work fine for turning off the castShadow from the gameobject this is attached to. Are you saying it did not, or you asking how to turn off all shadows in the entire scene?

avatar image PaxStyle · Mar 24, 2014 at 07:20 PM 0
Share

I asked for disable all shadows in the scene. :)

avatar image the_genius · Mar 24, 2014 at 07:48 PM 0
Share

If you are using a directional light:

https://docs.unity3d.com/Documentation/ScriptReference/LightShadows.None.html

1 Reply

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

Answer by Simon-Larsen · Mar 24, 2014 at 07:49 PM

If you've baked the lights in your scenes, then this will not work. But what you can do it fetch all the lights in your scene. Warning: This may be a heavy action and make your game lag, so I've put it in the Start function, which means it caches your lights before you actually start playing. (Having tested the code, so let me know if it gives you errors)

 import System.Collections.Generic;
 
 var lightDict = new Dictionary.<Light,LightShadows>();
  
 function Start() {
     for (var light : Light in FindObjectsOfType(Light) as Light[]) {
         lightDict[light] = light.shadows;
     }
 }
  
 function OnGUI (){
    if(GUI.Button(new Rect(100,200,200,70),"")){
        for (var light in lightDict.Keys) {
                if (light.shadows == LightShadows.None)
                    light.shadows = lightDict[light];
                else
                    light.shadows = LightShadows.None;
        }
    }
 }
    
Comment
Add comment · Show 3 · 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 PaxStyle · Mar 25, 2014 at 02:45 PM 0
Share

This work, but one time that i disabled the shadows, if i re-click on the button, they don't appear anymore.. i would like that if i click, they disappear, but if i click again the button they appear.

Sorry for my english D:

avatar image Simon-Larsen · Mar 25, 2014 at 03:02 PM 0
Share

I changed up the code a bit for you. It will now disable and re-enable all of your shadows as you click the button

avatar image PaxStyle · Mar 25, 2014 at 03:33 PM 0
Share

thank you

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

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

Related Questions

Realtime shadows not working on compatible video card 2 Answers

Reflection probe baked shadows fails at 2K, but works at 1K 0 Answers

Disable Lightmap when baked lights turn off 0 Answers

Baked + Real-Time Shadows 6 Answers

No shadows in the game, but there are in the editor. 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