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 siones1172 · Mar 29, 2019 at 01:48 AM · selection

Character selection for a team??

Alright, so I have a character select scene and I have 4 platforms with buttons for a player to choose between 4 characters to make a team. I have a character container and a script for selecting the characters and buttons that represents each character. Almost everything is working but my first problem is I can only select one character and my second problem is referencing the selected character and setting them active in the position and rotation of the selected platform. For my first problem I was thinking of adding an array, but I need help executing it as well as I need help transforming the position of the selected character. My script that works is

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CharacterContainer : MonoBehaviour
 {
     private List<GameObject> characters;
     private int selectionIndex = 0;
 
     private void Start()
     {
         characters = new List<GameObject>();
         foreach(Transform t in transform)
         {
             characters.Add(t.gameObject);
             t.gameObject.SetActive(false);
         }
 
         characters[selectionIndex].SetActive(true);
 
     }
 
     public void Select(int index)
     {
         if(index == selectionIndex)
             return;
 
         if(index < 0 || index >= characters.Count)
             return;
 
         characters[selectionIndex].SetActive(false);
         selectionIndex = index;
         characters[selectionIndex].SetActive(true);
     }
 }
 

And the edits that I began on the script are

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CharacterContainer : MonoBehaviour
 {
     private List<GameObject> characters;
     private int selectionIndex = 0;
     public Transform Player1SpawnPoint;
     public Transform Player2SpawnPoint;
     public Transform Player3SpawnPoint;
     public Transform Player4SpawnPoint;
     public bool platformActive;
 
     private void Start()
     {
         characters = new List<GameObject>();
         foreach(Transform t in transform)
         {
             characters.Add(t.gameObject);
             t.gameObject.SetActive(false);
         }
 
         characters[selectionIndex].SetActive(true);
 
     }
 
     public void Select(int index)
     {
         if(index == selectionIndex)
             return;
 
         if(index < 0 || index >= characters.Count)
             return;
 
         characters[selectionIndex].SetActive(false);
         selectionIndex = index;
         characters[selectionIndex].SetActive(true);
     }
      //////Transform the position on selected platform
      if (platformActive)
 {
 characters[selectionIndex].transform.Translate(Player1SpawnPoint.position, Player1SpawnPoint.rotation;)
 }
 }
 

I was gonna have 4 platformActive listed, but the first one didn't work. I hit a wall.

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 siones1172 · Mar 30, 2019 at 02:14 PM

Update: I have the idea to duplicate the selection script and assign them to the each character, button. It seems to work, but is there a way that I can call for 4 selections with one script?

Comment
Add comment · 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

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

101 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

Related Questions

selected object in array lost in translation 0 Answers

Quests/Dialogue (C#) 0 Answers

Managing and Referencing Attached Scripts Best Practice? 2 Answers

Selecting imported geometry selects ALL the geometry and uncontrollable for multiple objects 1 Answer

Trying to make gameObjects the target on right click 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