Author Topic: Input OnSubmit event?  (Read 7758 times)

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Input OnSubmit event?
« on: August 28, 2012, 02:11:29 PM »
what am i doing wrong...it seems to be working but i get the error about event -> "The best match for method OnSubmit has some invalid parameter."

here is the code that i attached to Input control

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class InputControl : MonoBehaviour {
  5.        
  6.         public GameObject InputField;
  7.        
  8.         void OnEnable()
  9.         {
  10.                 UIEventListener.Get(InputField).onSubmit += OnSubmit;  
  11.         }
  12.        
  13.         void Start()
  14.         {
  15.                 if(PlayerPrefs.HasKey("Player Name"))
  16.                 {
  17.                         InputField.GetComponent<UIInput>().label.text = PlayerPrefs.GetString("Player Name");
  18.                 }
  19.                
  20.                
  21.         }
  22.        
  23.         void OnSubmit(GameObject go)
  24.         {
  25.                 if(PlayerPrefs.HasKey("Player Name"))
  26.                 {
  27.                         PlayerPrefs.SetString("Player Name", go.GetComponent<UIInput>().text);
  28.                         PlayerControl.Name = PlayerPrefs.GetString("Player Name");
  29.                 }
  30.                 else
  31.                 {
  32.                         Debug.Log("No key");   
  33.                 }
  34.                
  35.                 Debug.Log("Name: " + PlayerPrefs.GetString("Player Name"));
  36.         }
  37. }
  38.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Input OnSubmit event?
« Reply #1 on: August 28, 2012, 03:38:26 PM »
OnSubmit doesn't have a game object parameter. In fact, it has no parameters.

PhilipC

  • Guest
Re: Input OnSubmit event?
« Reply #2 on: August 28, 2012, 04:06:13 PM »
Mike is actually wrong in this case. By using "UIEventListener.Get(InputField).onSubmit += OnSubmit;" you should pass a GameObject. But where your error is coming from im not sure at all as everything looks proper. Are you sure its coming from this line?