Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 justadeveloper · Jan 09, 2016 at 10:45 PM · uipositionrandomrecttransformanchor

this code doesnt work when the buttons anchor are not same(custom anchor)

this code works only if the buttons have same anchor presets but it doesnt work when buttons have different anchor presets(custom) how to make this work?

 using UnityEngine;
 using System.Collections;
 
 
 public class ShuffleChoice : MonoBehaviour 
 {
     public GameObject option1;
     public GameObject option2;
     public GameObject option3;
     public GameObject option4;
     
     bool stat2=false;
     bool stat3=false;
     bool stat4=false;
 
     public float x;
     public float y;
     public int mover;
     public int before=1;
     public int movequestion=0;
 
     public int count=1;
 
     // Use this for initialization
     void Start () 
     {
         RectTransform choice1 = option1.GetComponent<RectTransform> ();
         RectTransform choice2 = option2.GetComponent<RectTransform> ();
         RectTransform choice3 = option3.GetComponent<RectTransform> ();
         RectTransform choice4 = option4.GetComponent<RectTransform> ();
 
         x = choice1.anchoredPosition.x;
         y = choice1.anchoredPosition.y;
 
 
         do 
         {
             randomcount();
             if (randomcount () == 2 && stat2 == false)
             {
                 if(count==1)
                 {
                     choice1.anchoredPosition = new Vector2 (choice2.anchoredPosition.x,choice2.anchoredPosition.y);
                     choice2.anchoredPosition = new Vector2 (x, y);
                 }
 
                 else if(before==3)
                 {
                     choice3.anchoredPosition = new Vector2 (choice2.anchoredPosition.x, choice2.anchoredPosition.y);
                     choice2.anchoredPosition = new Vector2 (x, y);
                 }
 
                 else if(before==4)
                 {
                     choice4.anchoredPosition = new Vector2 (choice2.anchoredPosition.x, choice2.anchoredPosition.y);
                     choice2.anchoredPosition = new Vector2 (x, y);
                 }
 
                 x = choice2.anchoredPosition.x;
                 y = choice2.anchoredPosition.y;
 
                 count++;
                 stat2 = true;
                 before=2;
                 //Debug.Log ("count=" + count);
             } 
             else if (randomcount () == 3 && stat3 == false)
             {
                 if(count==1)
                 {
                     choice1.anchoredPosition = new Vector2 (choice3.anchoredPosition.x, choice3.anchoredPosition.y);
                     choice3.anchoredPosition = new Vector2 (x, y);
                 }
 
                 else if(before==2)
                 {
                     choice2.anchoredPosition = new Vector2 (choice3.anchoredPosition.x, choice3.anchoredPosition.y);
                     choice3.anchoredPosition = new Vector2 (x, y);
 
                 }
             
                 else if(before==4)
                 {
                     choice4.anchoredPosition = new Vector2 (choice3.anchoredPosition.x, choice3.anchoredPosition.y);
                     choice3.anchoredPosition = new Vector2 (x, y);
                 }
                 
                 x = choice3.anchoredPosition.x;
                 y = choice3.anchoredPosition.y;
 
                 count++;
                 stat3 = true;
                 before=3;
         }
         
         else if (randomcount () == 4 && stat4 == false)
             {
                 if(count==1)
                 {
                     choice1.anchoredPosition = new Vector2 (choice4.anchoredPosition.x, choice4.anchoredPosition.y);
                     choice4.anchoredPosition = new Vector2 (x, y);
                 }
 
             else if(before==2)
             {
                 choice2.anchoredPosition = new Vector2 (choice4.anchoredPosition.x, choice4.anchoredPosition.y);
                 choice2.anchoredPosition = new Vector2 (x, y);
             }
             
             else if(before==3)
             {
                 choice3.anchoredPosition = new Vector2 (choice4.anchoredPosition.x, choice4.anchoredPosition.y);
                 choice4.anchoredPosition = new Vector2 (x, y);
 
             }
 
                 x = choice4.anchoredPosition.x;
                 y = choice4.anchoredPosition.y;
                 
                 count++;
                 stat4 = true;
                 before=4;
                 //Debug.Log ("count=" + count);
         }
         } while(count<=3);
     }
 
     void update()
     {
         //randomcount ();
     }
     
     int randomcount()
     {
         mover = Random.Range (1,5);
         return mover;
     }
 
 }
 
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Set Rect Transform Screen Position 0 Answers

Stretching 90° rotated RectTransform to the size of the Canvas 0 Answers

Code thinks RectTransforms position is (0,0,0) 1 Answer

Get position of specific letter in UI Text 4 Answers

Anchor doesn't affect objects inside of another object 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges