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 AkuIrako · Nov 08, 2018 at 09:45 AM · 2dbuttonvariablesclick

How to get to pass multiple informations through button click ?

Hello everyone, My problem is I guess pretty simple but I'm still a beginner with Unity, and although I've searched everywhere I can't seem to find how to do exactly what I want. I have a button that everytime when clicked on, instantiates a new character sheet with random features (name, experience, etc) and puts it under the previous one so you get a list of characters. When clicking on the "managing" button on a character sheet, you should have access to another sheet where the character informations are written. So, I've made a managing sheet template and I can't find how to put the good informations on it depending what character was clicked. I thought of making an array or something but I need the informations to be able to change, like when you gain experience etc. Thank you !

Comment
Add comment · Show 2
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 Bonfire-Boy · Nov 08, 2018 at 04:50 PM 0
Share

I'm presu$$anonymous$$g that you have a "CharacterSheet" script or somesuch attached to each character sheet, that fills in the specific character's information on each instance. So that should know what character it relates to. $$anonymous$$ake the click event for the "managing" button on each character sheet call a function on that sheet's CharacterSheet script. This function can then bring up the "managing sheet" and tell it which character is to be managed.

avatar image AkuIrako Bonfire-Boy · Nov 08, 2018 at 08:26 PM 0
Share

I do have a script that's attached to each of my characters and that contains each variable about them. I also have a list in which all the characters are stocked. The character scripts are on objects that are parents to the button, so my problem is that when a button is pressed, it has to access the button's parent to know the ID, but I don't really know how to do that... When the button is clicked, I have a function in my Game$$anonymous$$anager that triggers another function in my $$anonymous$$anaging$$anonymous$$anager (sorry ahah), which is used to fill the managing sheet with the good informations.

This is the script part that instantiates a character :

 public void OnNouveauGroupe()
     {
         spawnPoint = spawnOrigin.transform.position.y;
         GameObject groupe = Instantiate(groupeFiche, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
         nombreQueens += 1;
         Queen tmpQueen = groupe.GetComponent<Queen>();
         tmpQueen.queenID = nombreQueens;
         queens.Add(tmpQueen);
         
         groupe.GetComponentInChildren<Button>().onClick.AddListener(() => Game$$anonymous$$anager1._instance.On$$anonymous$$anagingClicked());
         groupe.transform.SetParent(GameObject.Find("Background_queens").transform);
         groupe.transform.position = new Vector3(0, spawnPoint + (-(nombreQueens-1) * spacing), 0);
         groupe.transform.localScale = new Vector3(1, 1, 1);
 
         nouveauGroupe.transform.position = new Vector3(0, spawnPoint + (-nombreQueens * spacing) + 0.5f, 0);
     }

The script when the $$anonymous$$anaging button is clicked :

public void On$$anonymous$$anagingClicked() { background.gameObject.SetActive(false); shop.gameObject.SetActive(false); groupes.gameObject.SetActive(false); leaderboard.gameObject.SetActive(false); managing.gameObject.SetActive(true); //shows the good canvas m$$anonymous$$anager.On$$anonymous$$anaging(PARA$$anonymous$$ETER WHICH ID$$anonymous$$ HOW TO FILL); //triggers another function in the $$anonymous$$anaging$$anonymous$$anager script }

This is the function that's triggered in another script :

 public void On$$anonymous$$anaging(int ID)
     {
         Debug.Log(ID);
         Queen tmpQueen = GetComponent<Groupes$$anonymous$$anager>().queens[ID];
 
         tNom.text = tmpQueen.nom;
      }

$$anonymous$$y main concern for the moment is not knowing how to fill the parameter from the "On$$anonymous$$anagingClicked function"...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hectorux · Nov 08, 2018 at 03:13 PM

Try to create a class that store the info, and pass it to the button

Comment
Add comment · Show 16 · 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 AkuIrako · Nov 08, 2018 at 08:27 PM 0
Share

I did make a class, and each of my characters are stored in a list, but my main problem is that the $$anonymous$$anaging button is a child of the gameobject that's got the script on it and I don't know how to access it..

avatar image hectorux AkuIrako · Nov 08, 2018 at 08:54 PM 0
Share

You can make a script for every button that gets the character from its parent, somehing like:

public void GetCharacter(){

something.Chracter=transform.parent.getComponent();

} and this script atached to every button and set it on the button listerners list

avatar image AkuIrako hectorux · Nov 08, 2018 at 10:20 PM 0
Share

Thanks for your help !

I've made this script, and each button does get the good informations from its parent.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Bouton : $$anonymous$$onoBehaviour {
 
     public string nom;
     public string activite;
     public string nvXp;
     public int popularite;
     public int motivation;
     public int experience;
     public int queenID;
     public bool dispo;
     public int nbSpectacles;
     public int salaire;
 
     // Use this for initialization
     void Start ()
     {
         Queen qScript = gameObject.GetComponentInParent<Queen>();
     }
     
     // Update is called once per frame
     void Update ()
     {
         OnVarUpdate();
     }
 
     public void OnVarUpdate()
     {
         nom = gameObject.GetComponentInParent<Queen>().nom;
     }
 }

I get to launch it within another script, when the button is clicked :

     public void On$$anonymous$$anagingClicked()
     {
         background.gameObject.SetActive(false);
         shop.gameObject.SetActive(false);
         groupes.gameObject.SetActive(false);
         leaderboard.gameObject.SetActive(false);
         managing.gameObject.SetActive(true);
         m$$anonymous$$anager.On$$anonymous$$anaging(gameObject.GetComponent<Bouton>().queenID);
     }

But I'm getting an error :

![alt text][1] [1]: /storage/temp/127454-unity-2018-11-08-23-19-23.png

Which refers to this very line :

     m$$anonymous$$anager.On$$anonymous$$anaging(gameObject.GetComponent<Bouton>().queenID);

And I don't really understand what it refers to, because I've always been careful with my objects.

unity-2018-11-08-23-19-23.png (66.8 kB)
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

204 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 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

Colored border of button with GUI skin 0 Answers

RepeatButton AND Button at the same time 1 Answer

Make use of a button in a drop down menu? 0 Answers

How to make unity expect a click 0 Answers

Only want to detect button click event 1 Answer


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