进入www文件夹,右键新建文本文档,起名为helloWorld.php, 用记事本打开,输入如下代码,保存。
<?php
//echo 类似cout 或者 print,即在网页中输出文本内容
echo "Hello World!";
?>
之后,打开浏览器输入 http://localhost/helloWorld.php,页面结果如下。
新建unity工程, 创建一个物体,创建脚本GetEcho,把脚本拖到物体上,脚本如下
using UnityEngine;
using System.Collections;
public class GetEcho : MonoBehaviour {
void OnGUI()
{
if(GUI.Button(new Rect(0,0,100,50),"GetEcho"))
{
StartCoroutine(GetText());
}
}
IEnumerator GetText()
{
WWW myWWW = new WWW("http://localhost/helloWorld.php");
yield return
myWWW;
print(myWWW.text);
}
}
运行,点击左上角按钮,即在控制台输出了网页上的HelloWorld语句,怎么样,简单吧?
![【风宇冲】Unity3D教程宝典之Web服务器篇:(第三讲)PHP的Hello <wbr>World 【风宇冲】Unity3D教程宝典之Web服务器篇:(第三讲)PHP的Hello <wbr>World](https://i-blog.csdnimg.cn/blog_migrate/f14df737ffa0e5f5211493975e7e1dba.jpeg)