- Home /
Trying to Sort Layer based on Y coordinates
I'm trying to write a code that will change the layer of the player based on what its y coordinates are.
LayerChanger.cs
public class LayerChanger : MonoBehaviour
{
public int LayerPos;
public float LayerY = 41f;
public GameObject Player;
void Update ()
{
if (transform.position.y < LayerY) //checking if object reached LayerY in x direction
{
Player.layer = LayerPos;
} else
{
Player.layer = 5;
}
}
}
Comment