- Home /
Return 2 FLOAT from 1 VOID
hi, i have to make a button on the new UI of unity, to semplify my work i want to set 2 float directly from the buttons in the editor. usually i use something like this:
 public float ExampleToSet;
 
 public void Example (float ExampleFloat)
 {
  ExampleToSet = ExampleFloat;
 }
and i set ExampleFloat from a field in the editor, but if i try to wrote something like this:
     public float ExampleToSet;
     
     public void Example (float ExampleFloat1, float ExampleFloat2)
     {
      ExampleToSet = ExampleFloat1 + ExampleFloat2;
     }
in the button editor [on click()] i can't set Example as a function.
any help? thanks in advance
Answer by Cherno · Jul 15, 2015 at 09:31 PM
- You are talking about passing parameters, not return types. 
- Add the desired function as a Listener via script. Only one parameter is possible, but you can circumvent this by using a custom class instance as the parameter, which in turn may contain as many variables as you wish. - public Button button; public float float1; public float float2; public float exampleToSet; void Start() { ButtonParameter buttonParameter = new ButtonParameter (float1, float2); button.onClick.AddListener(delegate { Example (buttonParameter ); }); } public void Example (ButtonParameter buttonParameter ) { exampleToSet = buttonParameter.exampleFloat1 + buttonParameter.exampleFloat2; } [System.Serializable] public class ButtonParameter { public float exampleFloat1; public float exampleFloat2; public ButtonParameter() {} public ButtonParameter(float f1, float f2) { exampleFloat1 = f1; exampleFloat2 = f2; } }
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
UI Instantiate?,Ui, Sumonar UI? 0 Answers
make increment and decreasement button with if statement didn't work? 1 Answer
Setting negative value for rectTransform sizedelta !!! 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                