- Home /
Change Object Layer
Hey guys I can't seem to find a clear answer, figured I would ask. How would I change the layer of an Object when the player is near? Some kind of collision perhaps?
Answer by Krizzu · Jun 17, 2014 at 08:43 AM
I would add Box Collider to this object and check isTriggered on it, make it big enough to suits your needs. Then, in script, I would check if Collision is existing -> then change Collider's layer to another.
yeah that's basically what I was thinking. Not sure how to write any script, I'm awful at it lol
Is it a sorting layer that you are trying to change? If so take a look at the SortingLayer attributes of GameObject.renderer:
User layers. I need to switch between two layers. Example, there is a BOX with layer A. When you touch a collider, the box will change to Layer B. When you leave the collider, it will return back to Layer A.
I wrote this script but it doesn't seem to work right. When the game starts it changes it's layer. function OnTriggerExit(){ gameObject.layer = 11; } function OnTriggerEnter(){ gameObject.layer = 12; } Anyone know what it's missing?
Your answer
Follow this Question
Related Questions
How do I check to see if animation layer is playing with hash id on Unity3d 0 Answers
Is there a way to mask out a sprite layer 0 Answers
Physics linecast ignoring layers 0 Answers
I need my GameObject to Spawn in front of my sprites 2 Answers
When i press Jump, i am allowed to double/triple jump even though i called for a capsule check? 2 Answers