- Home /
Question by
otaldojuca · Nov 27, 2020 at 06:39 PM ·
c#instantiateunity 2dcanvas
Why is my default Z set as -4000?
When I instantiate the game object inside my Canvas, its X and Y are set correctly, but my Z is set to -4000. The "order in layer" of my canvas is 5.
// (...)
private RectTransform rectTransform;
private CanvasGroup canvasGroup;
float spawnPositionX;
float spawnPositionY;
private void Awake() {
rectTransform = GetComponent<RectTransform>();
canvasGroup = GetComponent<CanvasGroup>();
spawnPositionX = transform.position.x; //
spawnPositionY = transform.position.y; //
}
// (...)
public void OnEndDrag(PointerEventData eventData) {
Debug.Log("OnEndDrag");
canvasGroup.alpha = 1f;
canvasGroup.blocksRaycasts = true;
GameObject iconSubs = Instantiate(gameObject, new Vector2(spawnPositionX, spawnPositionY), Quaternion.identity, GameObject.FindWithTag("Canvas").transform);
}
// (...)
Comment
Your answer
Follow this Question
Related Questions
Object Instantiate Image to Canvas, Object destroy, Image destroy? 1 Answer
How do you Instantiate Text as Child of Canvas c# 1 Answer
How do you Instantiate a button as a child object of a canvas? 0 Answers
Unexpected symbol 'Instantiate' [SOLVED] 1 Answer
Instantiated object not showing in scene or hierarchy 2 Answers