Instantiate changes position
Aloha,
Right now i am fighting with a instantiate of an existing button and placing it some pixels above it..
So now i am just trying to copy this button via C# code..
public GameObject answerButton;
public GameObject canvas;
private GameObject answerButton1;
//
answerButton1 = Instantiate(answerButton,new Vector3(answerButton.transform.position.x, answerButton.transform.position.y - 50, answerButton.transform.position.z),answerButton.transform.rotation);
var rectTransform = answerButton1.GetComponent<RectTransform>();
rectTransform.SetParent(canvas.transform);
And that works actually..but the coordinates of this button...are screwed up :<
The image quality isn't good as was planned :)
Well, the thing is, that the position and scaling of a clone button has changed
answerButton1 = Instantiate(answerButton, answerButton.transform.position, answerButton.transform.rotation) as GameObject;
var rectTransform = answerButton1.GetComponent<RectTransform>();
rectTransform.SetParent(canvas.transform);
rectTransform.transform.position = new Vector3(answerButton.transform.position.x, answerButton.transform.position.y + 0.8f, answerButton.transform.position.z);
rectTransform.transform.localScale = answerButton.transform.localScale;
That was my solution.. But i hope to find a better one answer
Answer by Arogunz · Aug 17, 2017 at 11:08 AM
My problem is solved. You have to avoid putting a canvas into another canvas. Use Panels.
Your answer
Follow this Question
Related Questions
How do you make a clone have the same tag as its original? 0 Answers
Instantiate problem, spawning too many clones, then cloning the clones! help! 0 Answers
Bullet clones will not be destroyed. 2 Answers
How to create an array of clones for a seperate Save/Load script 0 Answers
instantiating problem??? 2 Answers