- Home /
[Solved]Why my Unity Button's Positions are different.
Ok. So I want to make some kind of animation, so when I press on the main button others buttons it will be displayed in an circular mode around that main button. But the problem is that their positions are not where it should be. This is how I want it to be.
And this is how its position after I place them.
This is the code
using UnityEngine;
using System.Collections;
public class PieMenu : MonoBehaviour {
public int numPoints = 20;
public Vector3 centerPos = new Vector3(0,0,32);
public GameObject[] pieObj;
public float radiusX,radiusY;
public bool isCircular = false;
public bool vertical = true;
Vector3 pointPos;
void Start()
{
for(int i = 0; i<numPoints;i++){
//multiply 'i' by '1.0f' to ensure the result is a fraction
float pointNum = (i*1.0f)/numPoints;
//angle along the unit circle for placing points
float angle = pointNum*Mathf.PI*2;
float x = Mathf.Sin (angle)*radiusX;
float y = Mathf.Cos (angle)*radiusY;
//position for the point prefab
if(vertical)
pointPos = new Vector3(x, y)+centerPos;
else if (!vertical){
pointPos = new Vector3(x, 0, y)+centerPos;
}
Debug.Log(pointPos);
Debug.Log(i);
//place the prefab at given position
pieObj[i].transform.position = pointPos;
}
//keeps radius on both axes the same if circular
if(isCircular){
radiusY = radiusX;
}
}
}
Thats because of the canvas because if I'm testing with simple sprites everything works.
Answer by Gaming-Dudester · May 17, 2015 at 09:44 PM
Have you tried putting all the anchors to the top left corner of the screen?
Yes I did, I tried every anchor but the position is almost the same as in the picture above.
Your answer
Follow this Question
Related Questions
How do I create an Image of certain size in the middle of the screen with stretching border images 0 Answers
Tutorials for 2D game GUI 2 Answers
I'm trying to make a UI object move from one position to another over time 0 Answers
Image ui point at mousse position 0 Answers
How to get accurate x/y for Rectangle Transform of Panel under canvas? 2 Answers