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 /
This question was closed Feb 22, 2019 at 07:46 PM by RuteMatos.
avatar image
0
Question by RuteMatos · Jan 29, 2019 at 10:25 PM · androidbuttontesting

Unity button desabling not working on Android device

I am using Unity for the first time.

I am making a app to work on Android platform.

I made a script to add to one button. The interface has a text input field to add names of a group. After writing some name and hit one button (adicionar), it should add the name in a text field (named textoGrupo). It would also enabled a second button (named seguinte), that would be disabled since the begining of the script execution. I also have another text field (textoElementoRepetido) that should have text only if the name written is repeated.

It works fine when I tested it in Unity. But when I test it on my Android device it does nothing of what's on the script.

Here is my code:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.Data; using Mono.Data.SqliteClient; using TMPro; using System.IO;

public class grupo : MonoBehaviour { List elementos = new List(); private IDbConnection connection; private IDbCommand command; string dbFile;

 int idGrupo = 0;
 public TMP_InputField input;
 public TMP_Text textoGrupo;
 public TMP_Text textoElementoRepetido;
 public Button seguinte;


 // Start is called before the first frame update
 IEnumerator Start()
 {
     
     // Ligação à base de dados
     string filepath = Application.persistentDataPath + "/TVdatabase.db";

     if (!File.Exists(filepath))

     {
         // if it doesn't ->
         // open StreamingAssets directory and load the db ->
         WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/TVdatabase.db");  // this is the path to your StreamingAssets in android

         while (!loadDB.isDone)
         {
             yield return new WaitForSeconds(30);
         }  // CAREFUL here, for safety reasons you shouldn't let this while loop unattended, place a timer and error check

         // then save to Application.persistentDataPath

         File.WriteAllBytes(filepath, loadDB.bytes);

     }

     //open db connection

     connection = new SqliteConnection("URI=file:" + filepath);

     seguinte.interactable = false;

 }

 public void AdicionaElemento( )
 {
     if (input.text != null && input.text != "")
     {
         string sql;

         //se ainda não existirem elementos no grupo, é criado na base de dados um grupo e o seu id é guardado

         if (elementos.Count == 0)
         {
             command = connection.CreateCommand();
             connection.Open();

             sql = "INSERT INTO Grupo(idAvatar) VALUES(1);";
             command.CommandText = sql;
             command.ExecuteNonQuery();

             sql = "SELECT MAX(idGrupo) FROM GRUPO;";
             command.CommandText = sql;
             IDataReader reader = command.ExecuteReader();

             while (reader.Read())
             {
                 idGrupo = reader.GetInt32(0);
             }
             connection.Close();
         }
         string elemento = input.text.ToString();

         if (!elementos.Contains(item: elemento))
         {
             textoElementoRepetido.text = "";

             command = connection.CreateCommand();
             connection.Open();

             sql = "INSERT INTO Elemento(nomeElemento, idGrupo) VALUES('" + elemento + "', " + idGrupo + ");";

             command.CommandText = sql;
             command.ExecuteNonQuery();

             connection.Close();

             if (elementos.Count == 0)
             {
                 textoGrupo.text += elemento;
             }
             else
             {
                 textoGrupo.text += ", " + elemento;
             }
             elementos.Add(elemento);
             seguinte.interactable = true;
             input.text = "";
         }
         else
         {
             textoElementoRepetido.text = "Essa pessoa já faz parte do teu grupo!";
         }
     }
      else{
          seguinte.interactable = false;
      }
 }


 // Update is called once per frame
 void Update()
 {
     
 }

} alt text

I hope I wrote enough to understand the purpose of this screen. Here is what I attached to the button adicionar.

attached on button

If first tried it on the onClick() event. Didn't work. So I tried it on a trigger. Same result.

I have no idea why this works on unity editor but not on my Android device and I really need to make this work in some time really soon. Can someone please help me?

Update I now know that the problem is somewhere in the data base connection. Because the script works fine when I press the button Adicionar without anything on the text input field.

I also have this question here with more updates.

sem-titulo.png (34.3 kB)
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

  • Sort: 
avatar image
1

Answer by misher · Jan 30, 2019 at 08:45 AM

 seguinte.interactable = false;

is never reached.

There should be an exception happened before that line of code. Use Android studio logcat tool to find the problem.

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

Follow this Question

Answers Answers and Comments

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

Taking Input from Android phones 1 Answer

Scaling the GUI matrix in mobile causes buttons to be off 1 Answer

Why is it that when i click on a gui element it sends a mousedown and mouseup to the LAST gameobject that i clicked? 0 Answers

Button highlight not intended on Android and iOS 0 Answers

How do I make my player jump on click on the button? 3 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