- Home /
How can I change the layer of a GameObject?
I looked at http://docs.unity3d.com/Documentation/ScriptReference/GameObject-layer.html so I did this
var theEnemy = GameObject;
function Attack ()
{
theEnemy.layer = 8;
}
I get the error
Assets/Scripts/Weapons/RayCastCloseCombat.js(59,26): BCE0019: 'layer' is not a member of 'System.Type'.
I'm not sure why it did not work.
PS I'm changing the layer of the enemies so that when the player attacks the knife will go through the enemy not draw on top of it.
Comment
Answer by Puradox · Jan 06, 2014 at 04:51 PM
Change
var theEnemy = GameObject;
to
var theEnemy : GameObject;
The reason why your old code didn't work is because you haven't specified theEnemy as a GameObject correctly; therefore, Unity is treating it as a general javascript variable, which isn't what you want.
Your answer
![](https://koobas.hobune.stream/wayback/20220613125706im_/https://answers.unity.com/themes/thub/images/avi.jpg)