Unity2D trouble positioning object in script
I have a pretty basic setup where I have a canvas that is set to screen space with my main render camera. In my script I instantiate a gameObject "Panel", and in the layout element I have it set as "Ignore Layout". I then have a script setup to whenever I hold my mouse down, the panel is suppose to move with my mouse coordinates. Almost everything works as expected except the problem is that when I move my mouse around the panel never moves beyond the very middle of the screen. If I move my mouse up and down, left and right, the panel does the same but it will never move beyond the upper-right quadrant of the canvas. It looks to my like the position (0,0) of the panel is actually the center of the canvas. The farthest bottom-left I can get the panel to go is (1109,640) which is the center of the canvas. If I explicitly in the script set the panel position to (0,0,0) it will still never move beyond the center screen, but if I set the position(0,0,0) in the inspector, it moves all of the way over just fine.
I am clearly missing something(s), if anyone knows what that is I would appreciate it.
Answer by MasterSniper · Apr 01, 2016 at 12:42 PM
I finally found the solution although I am not sure I full understand why this works,
dragablePanel.GetComponent<RectTransform>().anchoredPosition = new Vector3(Input.mousePosition.x*2, Input.mousePosition.y*2, 1);
Your answer
Follow this Question
Related Questions
Random position, overlap problem. 1 Answer
Changing Player Position when hit by collider 0 Answers
Help with Unity Networking and teleporting player 0 Answers
Trying to Generate Different Random Values for Position of Game Object Instances [C#] 1 Answer
position the player on the same position as an object 0 Answers