• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by uanmanarmy · May 17, 2015 at 08:45 PM · positioncanvasimagebuttonspanel

[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.

alt text

And this is how its position after I place them. alt text

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.

screenshot-12.png (14.5 kB)
screenshot-11.png (18.6 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image uanmanarmy · May 17, 2015 at 10:31 PM 0
Share

Yes I did, I tried every anchor but the position is almost the same as in the picture above.

avatar image uanmanarmy · May 22, 2015 at 10:19 PM 0
Share

I had to access the localPosition :D

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Tutorials for 2D game GUI 2 Answers

How do I create an Image of certain size in the middle of the screen with stretching border images 0 Answers

I'm trying to make a UI object move from one position to another over time 0 Answers

How to get accurate x/y for Rectangle Transform of Panel under canvas? 2 Answers

Image with transparency cut-offs as button 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges