- Home /
camera culling mask Layers
Hello
I am trying to switch the main camera culling mask
depending on what you collide with...
This is the script on the box:
Almost works.... but not
using UnityEngine;
using System.Collections;
public class boxCollision : MonoBehaviour
{
public bool boxToggle = false;
public int cullMask = 11;
void Update()
{
//Transform thisTransform = this.gameObject.transform;
//UpdateVRCameraTransform(thisTransform);
//TOGGLE CULLING MASK
if (boxToggle == false)
{
Camera.main.cullingMask = 1 << cullMaskTHREAD;
// ;
}
else { Camera.main.cullingMask = 1 << cullMask; }
}
void OnCollisionEnter(Collision collision)
{
boxToggle = true;
Camera.main.cullingMask = 1 << cullMask;
}
}
Thanks!
~be
Answer by getyour411 · Dec 13, 2016 at 01:50 AM
"but not" isn't a very good description so I don't know what's happening here; try this link to make working with layermasks easier (Scroll down)
http://answers.unity3d.com/questions/8715/how-do-i-use-layermasks.html
@getyour411 Thanks, but even with other ter$$anonymous$$ology it only works once That article was helpful, but the updated script still doesn't work : The script works on on object but not on any of the others (which are exactly the same)..?
public class boxCollision1 : $$anonymous$$onoBehaviour
{
public bool boxToggle = false;
public Layer$$anonymous$$ask defaultLayer;
public Layer$$anonymous$$ask myLayer;
void start()
{
defaultLayer = (1 << Layer$$anonymous$$ask.NameToLayer("THREAD"));
myLayer = (1 << Layer$$anonymous$$ask.NameToLayer("ROO$$anonymous$$"));
}
void Update()
{
//TOGGLE CULLING $$anonymous$$AS$$anonymous$$
if (boxToggle == false)
{
Camera.main.culling$$anonymous$$ask = defaultLayer;
}
else { Camera.main.culling$$anonymous$$ask = myLayer; }
}
void OnTriggerEnter(Collider other)
{
Debug.Log("collision");
boxToggle = true;
}
}
I know the layers are called correctly because I can switchthem on the object that works...
Any advice id helpful
Thanks!
~be
@getyour411 Thanks - but it only works once, even if I copy the object exactly - it wont work on the 2nd one... I even copied the script and changed the variable names and that wont work ...
Weird
Your answer
Follow this Question
Related Questions
If camera renders Skybox some objects don't get shown 1 Answer
I can't hide a RawImagen in a camera view 1 Answer
Camera culling without layer mask 0 Answers
How can you hide Canvas objects using Camera Culling Mask? 1 Answer
How to show part of the screen only for specified sorting layer? 0 Answers