Question by
Dreamwalker12 · Nov 18, 2016 at 07:44 AM ·
scripting beginnerprefabslayers
how to detect when a sprite is on a prefab/object?
i have a player sprite which is on a prefab object that was put in to unity by using the tiled to unity application.
Each of the prefabs i have imported have different layers and i am trying to figure out how to set my characters sorting order to be different when she moves from one prefab to another.
For example when she warps from outside of a building to inside a building, how do i make it so it detects she is on another object and change her sorting layer?
all i have so far is this but i know i'm missing a way to detect this.
private SpriteRenderer Sprite;
// Use this for initialization
void Start()
{
Sprite = GetComponent<SpriteRenderer>();
if (GameObject.Find("screen 1")) //checks if there is an object on screen by the specified name
{ // then changes sprites layer
Sprite.sortingOrder = 5;
Debug.Log("Sprite has changed layer");
}
}
}
thank you for the help in advance :)
Comment