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 unity_G2yrNlWYdpJKuw · Dec 28, 2017 at 10:22 AM · unity 5characterselection

Character selection

Hello, does anyone know how to make a character selection like the one in the Ballz mobile game? I have watched a YouTube tutorial on how to do it and came up with this script :

 private List<GameObject> balls;
 private int selectionIndex = 0;

 private void Start()
 {
     balls = new List<GameObject>();
     foreach(Transform t in transform)
     {
         balls.Add(t.gameObject);
         t.gameObject.SetActive(false);

     }

     balls[selectionIndex].SetActive(true);
 }

 private void Update()
 {
     
 }

 public void Select(int index)
 {
     if (index == selectionIndex)
         return;

     if (index < 0 || index >= balls.Count)
         return;

     balls[selectionIndex].SetActive(false);
     selectionIndex = index;
     balls[selectionIndex].SetActive(true);
 }

Now, instead of the gameobjects to get inactive, what I want instead is to change the outline color of the gameobjects and change a text inside the gameobject. How would I do that? I'm still new to coding and have no idea.

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
Best Answer

Answer by Elisvaldo · Dec 28, 2017 at 12:30 PM

Most likely you'd like to add a component to the balls, something like BallSelectionBehaviour.

In that script you could have a public method called OnBallSelected(), where you'd do everything that you want, including the SetActive().

And finally, in your script, you would call balls[selectionIndex].GetComponent<BallSelectionBehaviour>.OnBallSelected() instead of the set active.

Note that GetComponent<> can get a bit heavy. It might be a good idea to store the BallSelectionBehaviour in a list, just like you did with the GameObject, and populate the list only once on Start. Another option would be a Dictionary<GameObject, BallSelectionBehaviour>.

From what I see, I'd also create a OnBallDeselected() and add there the SetActive(false). It is a good idea to have your things separated. So, next time you want to add some particles, e.g., when a ball is selected, you know exactly where to change the code.

Comment
Add comment · Show 5 · 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 unity_G2yrNlWYdpJKuw · Dec 28, 2017 at 05:59 PM 0
Share

Hello, thank you for your reply. When I change the balls[selectionIndex].SetActive(true); to balls[selectionIndex].GetComponent.OnBallSelected(); it gives me an error - Expression denotes a method group', where a variable', value' or type' was expected.

avatar image Elisvaldo unity_G2yrNlWYdpJKuw · Dec 28, 2017 at 06:52 PM 0
Share

You need to specify which component you want to get. In the case of my example, it would be balls[selectionIndex].GetComponent<BallSelectionBehaviour>().OnBallSelected(). Ins$$anonymous$$d of BallSelectionBehaviour just put the name of the $$anonymous$$onoBehaviour you have attached to the ball with the public method OnBallSelected().

avatar image unity_G2yrNlWYdpJKuw Elisvaldo · Dec 28, 2017 at 06:57 PM 0
Share

Oh gosh, I'm stupid! Yeah, I'll try, thanks.

Show more comments
Show more comments

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

163 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 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 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

How to connect multiple stats scripts for the actual character stats? 1 Answer

How to Get Next One On The Que? 0 Answers

Unity networking create & join with custom character?, 0 Answers

How do I make Character Model to change across all scenes if changed in Main Menu? 1 Answer

Does anyone know how to delete selections in Unity 5? 2 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