Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by VisualPath · Oct 28, 2016 at 02:00 PM · cameralayersculling mask

Camera Culling Mask Change

Hi guys,

I am pretty new to Unity and have a question. I have 2 scripts that are basically 2 flashlights.

First is a normal flashlight, and the second one is a UV light flashlight. (Same thing, but a different color to the light).

My problem is the following: I have created a new layer called UVlight (Layer 10).

I want the camera (PlayerCamera) to render everything, besides the UVlight layer. When the player turns his UVFlashlight on, the objects tagged with UVlight layer to become visible if the player shines the light over them.

Here is the flashlight script: using UnityEngine; using System.Collections;

 public class flashLight : MonoBehaviour {
 
     private Light fL;
     
     void Start()
     {
         fL = gameObject.GetComponent< Light >();
     }
     
     void Update()
     {
         if( Input.GetKeyDown( KeyCode.F ) )
         {
             if( fL != null) fL.enabled = !fL.enabled;      
         }
     }
 }

UV Flashlight Script:

 using UnityEngine;
 using System.Collections;
 
 public class flashLightUV : MonoBehaviour {
 
     private Light fLUV;
     
     void Start()
     {
         fLUV = gameObject.GetComponent< Light >();
     }
     
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.U))
         {
             if (fLUV != null)
             {
                 fLUV.enabled = !fLUV.enabled;
             }
         }
     }
 }
 

Any ideas on how to do this? I think it is a simple thing to do, but like I said, I'm kinda newbie at this and seek help from the more experienced devs.

Thanks in advance, Vlad

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

3 Replies

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

Answer by Zynek · Oct 28, 2016 at 02:46 PM

Well a naive solution to this might be simply changing culling mask at runtime. For that you would just add something like this into your UV Flashlight script:

 //decleration
 [SerializeField] private LayerMask normalCMask;
 [SerializeField] private LayerMask uvCMask;
 
 //On UV light Turn on
 ...
 Camera.main.cullingMask = uvCMask;
 ...

And you would setup culling masks in the inspector. However more sofisticated solution would be to write your own shader, so the objects would be visible only if they are directly lit. There i cannot assist, but here is a tutorial on how to write shaders: https://youtu.be/epixwRw80MM

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 VisualPath · Oct 28, 2016 at 10:27 PM 0
Share

I tried this, but for some reason, it did not work. It did not change the cullingmask on the camera. Does it have to be the $$anonymous$$ainCamera? I use an Untagged camera, since this is the requirement of AdventureCreator.

avatar image Zynek VisualPath · Oct 28, 2016 at 10:41 PM 0
Share

The camera has to be tagget as "$$anonymous$$ainCamera" if you want to acces it through Camera.main.

But you can use this on any camera, you just need the right reference.

avatar image
0

Answer by Landerk · Oct 28, 2016 at 03:58 PM

You could have a camera set to render the UV layer, place it above your main camera so it renders everything. Disable/enable it with the flashlight script.

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 VisualPath · Oct 29, 2016 at 12:10 PM 0
Share

Thanks for the suggestion. I used Zynek's method and i managed to get things to work as intended.

avatar image
0

Answer by VisualPath · Oct 29, 2016 at 09:03 AM

Ok, so I'm dumb. I managed to make the Culling Mask change, but now I have a different problem. For the objects set on the UV Layer, I want them to be visible only when the UVFlashlight shines over them. And for example if the light shines only on one part of the object, I only want that part to be visible, and not the entire object.

Is there any way i could do that?

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 Zynek · Oct 29, 2016 at 09:07 AM 0
Share

As i said, that requiers advanced aproach and most likely writing your own shader, but you can check out shaders at asset store, if anyone already made what youre looking for.

avatar image VisualPath · Oct 29, 2016 at 12:10 PM 0
Share

Ok, i managed to change the way i use the light and everything looks good now, and works as intended. Thanks for your help!

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

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

Related Questions

Hiding Spotlight from only 1 camera 0 Answers

Can you still hit the collider of an object that's been culled via a camera's culling mask? 1 Answer

[SOLVED]Why my culling mask don't work? 1 Answer

Multiplayer Camera Layer Issues 1 Answer

Multiplayer Camera Layers 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