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 /
avatar image
0
Question by Sorcha_K · Jul 20, 2016 at 10:58 AM · layerssliderlayer mask

Loading layers using a slider

Hi guys, I'm brand new to Unity and C#, so please excuse my lack of familiarity with writing code. I currently have a script that loads layers by listening for a key down. The layers are tagged so only certain ones are loaded for certain keys. At the moment I only have one layer, but there will be more, so there are a few spare bits commented out in the code.

This has worked for me so far, so I'd like to use this same principle to load layers using a slider, so that certain layers are loaded when the slider reaches a certain value. The slider value range is between 1314 and 1600 and I'm trying to illustrate to the user how something changed over time. I am trying to adapt the code I'm already using (below, as it currently stands, working perfectly and listening for GetKeyDown) so that the input is the current slider value at the if statement, but I don't seem to be able to retrieve the slider value.

I've tried several combinations of declaring variables and public classes and getting errors every time. I know it should be something to do with the slider value being >= X but I can't quite get there. I'm sure there's something simple I'm missing. Would anyone be able to help or point me in the right direction?

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class layerLoad2 : MonoBehaviour {
 
     //declare ints to hold the layer mask bits
     int LoggiaDeiLanziLayerIndex;
     //also an int to hold the current mask and to hold
     //the new layer mask each time
     int currentCullingMask;
     int newLayerMask;
     bool LoggiaDeiLanziShown = true;
     //bool treesShown = true;
 
     // Use this for initialization
     void Start () {
         LoggiaDeiLanziLayerIndex = LayerMask.NameToLayer("LoggiaDei_Lanzi");
     }
 
     void showLayer(int showLayerIndex){
         currentCullingMask = GetComponent<Camera>().cullingMask;
         newLayerMask = 0;
         newLayerMask |= 1 <<  showLayerIndex;
         GetComponent<Camera>().cullingMask = (currentCullingMask | newLayerMask);
     }
 
     void hideLayer(int hideLayerIndex){
         currentCullingMask = GetComponent<Camera>().cullingMask;
         newLayerMask = 2147483647;
         newLayerMask  &= ~(1 << hideLayerIndex);
         GetComponent<Camera>().cullingMask = (currentCullingMask & newLayerMask);
     }
     public Slider
     // Update is called once per frame
     void Update () {
         //listen for specific keys to change the layers
         if (Input.GetKeyDown(KeyCode.T)) {
             //check the status 
             if(LoggiaDeiLanziShown){
                 //if Shown then hide
                 hideLayer(LoggiaDeiLanziLayerIndex);
                 LoggiaDeiLanziShown = false;
             }
             else{
                 //treesShown is hidden so show it!
                 showLayer(LoggiaDeiLanziLayerIndex);
                 LoggiaDeiLanziShown = true;
             }
         }
         
     }
 }



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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

using layers to mask where a player can see. 0 Answers

Post Processing v2 make the effect visible only on certain layer objects 2 Answers

Raycast ignore layers except 1 Answer

How can I mask a camera's display with an image? 0 Answers

Camera culling without layer mask 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