Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have a Raffle with Data from a Database, I create two tables one for the players and one for the winners. I want to get the data from the Public Text and use that data to store the info of the winner, using a Public string inputfield.

Any suggestion or help or a different approach would be nice!

Thanks in advance!

What I have tried:

C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DataInserter : MonoBehaviour
{

    string CreateGanadoresURL = "http://localhost/trivia/ganadores.php";

    public Text factura;

    public string inputFactura;
    public string inputRuc;
    public string inputNombre;

    // Use this for initialization
    void Start ()
    {
        inputFactura = factura.Text;//this is the 19
    }
    
    // Update is called once per frame
    void Update ()
    {
        if (Input.GetKeyDown(KeyCode.Space)) CreateGanadores(inputFactura, inputRuc, inputNombre);
    }

    public void CreateGanadores(string factura, string ruc, string nombre)
    {
        WWWForm form = new WWWForm();
        form.AddField("facturaPost", factura);
        form.AddField("rucPost", ruc);
        form.AddField("nombrePost", nombre);

        WWW www = new WWW(CreateGanadoresURL, form);
    }
}

And the error is:
Quote:
Assets/Scripts/DataInserter.cs(19,32): error CS1061: Type `UnityEngine.UI.Text' does not contain a definition for `Text' and no extension method `Text' of type `UnityEngine.UI.Text' could be found. Are you missing an assembly reference?
Posted
Updated 27-Sep-17 2:35am
v3
Comments
Graeme_Grant 26-Sep-17 21:04pm    
inputfield = txtInput.Text;

What am I missing here?
Graeme_Grant 26-Sep-17 21:17pm    
Ah, syntax error. You left out key information! Don't post the exception here, paste it in the question where others can see it.

Please take the time to read the rules section of the FAQ[^] to better understand how it works. Then when ready, update the question with clear and concise details, sample code, any error messages (including inner exception details), etc, by clicking on the Improve question widget.

The exception is the key to your problem. Go back to the documentation to see how you access the information: Unity - Scripting API: WWWForm[^]
chino96 26-Sep-17 22:33pm    
Sorry, I still dont know what to use from that page, I already have a script thats drags the winner to the text file(so already have the infromation) or maybe I miss something?
Graeme_Grant 26-Sep-17 22:42pm    
I don't use unity. I'm only pointing to the sample code of how to get text from the Unity documentation.
chino96 26-Sep-17 22:57pm    
oh, ok Thanks You! But Can I ask where I should use the inputfiel = txtInput.Text;? in void start or in void update?

1 solution

I just solved with the help of Grame_Grant! I had a T insted of t in the inputfield = txtInput.text

this is the final script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DataInserter : MonoBehaviour
{

    string CreateGanadoresURL = "http://localhost/trivia/ganadores.php";

    public Text factura;
    public Text ruc;
    public Text nombre;

    public string inputFactura;
    public string inputRuc;
    public string inputNombre;
    // Use this for initialization
    void Start ()
    {
        
    }
	
	// Update is called once per frame
	void Update ()
    {
        inputFactura = factura.text;
        if (Input.GetKeyDown(KeyCode.Space)) CreateGanadores(inputFactura, inputRuc, inputNombre);
        
    }

    public void CreateGanadores(string factura, string ruc, string nombre)
    {
        WWWForm form = new WWWForm();
        form.AddField("facturaPost", factura);
        form.AddField("rucPost", ruc);
        form.AddField("nombrePost", nombre);

        WWW www = new WWW(CreateGanadoresURL, form);
    }
}


Grame_Grant many many thanks to you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900