I was wondering if it was possible to make the unity plugin connect to the database and go like: If valiue1 = 1 { show. object1} . Like, I did this tamagochi script and I would like to have the creatures dynamicly depend on the database : ) so their appearace depends on the data in my database.
If it s possible, how would I do this ? I know the php and sql part. If someone could make me a script that shows a sphere if a value equals 1 and hide it when this value equals 0 per exemple, that would be awsome really.
I think my high scores work like this. Is this what you are looking for?
// the url of the php file to access.
var url="http://site.com/cooldirectory/awesome.php?style=";
GetSQL(url, 1); // start it
function GetSQL(url : String, style : int)
{
download = WWW(url + style); // start download
yield download; // wait until done
result = download.data; // What is returned from download.data is a string containing the php file's content (in html). The stuff written from the echo command
guiText.text = result; // put it on the gui
}
PHP:
<?php
$style = $_GET['style'];
// Send variables for the MySQL database class.
$database = mysql_connect('server', 'user', 'pass') or die('Could not connect: ' . mysql_error());
mysql_select_db('megapixel_scores') or die('Could not select database');
$query = "SELECT * FROM scores WHERE style=$style ORDER by score DESC LIMIT 5";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$num_results = mysql_num_rows($result);
for($i = 0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo $row['name'] . "\t" . $row['score'] . "\n";
}
?>
Warning, untested forum code that isn’t precisely what you asked for (it just shows an example of pulling data by calling a PHP file), but it should get the idea across:
// build URL and call file
var myURL = "http://www.yourserver.com/file.php";
var netOP = WWW(myURL);
// wait for the operation to complete
yield netOP;
// check for errors
if(netOP.error) {
// show your error message
} else {
// get the retrieved data
var netData = netOP.data;
// do something with that data...
}
You may end up needing to add URL parameters to the end of your URL (myURL in the example above) to guide the database query, but I’ll leave that as additional reading for you (WWW class).
Edit: hahahahaha, I guess I should have read Yoggy’s post before bothering to reply… :lol:
Thanks everyone, I apologise soo much for not replying. I just wanted to tsay I m really gratefull for your help. Sorry i couldnt thank you guys before. Finally Jeremy fixed my problem with some C# but in the same time, with your reply Yoggy you fixed one of my OTHER problem haha… SO yea. Thanks so much for your support guy, and on irc as well : )