調整AR拍攝距離
AR Camera > Camera > 調整屬性Field of View的數值
private void OnTrackingLost() //當目標物遺失就執行這方法
{
Renderer[] rendererComponents = GetComponentsInChildren(true);
Collider[] colliderComponents = GetComponentsInChildren(true);
/*
// Disable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = false; //把false改成true,當目標物遺失虛擬物件不會跟著消失
}
// Disable colliders:
foreach (Collider component in colliderComponents)
{
component.enabled = false; //把false改成true,當目標物遺失虛擬物件不會跟著消失
}
*/
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
}

using UnityEngine;
using System.Collections;
using System.IO;
using System.Net;
using UnityEngine.UI;
public class rankingboard : MonoBehaviour
{
public string url; //url是指要連結的php檔案位置,此範例為127.0.0.1/select.php
HttpWebRequest request;
void Update()
{
StartCoroutine (reflashboard ());
}
IEnumerator reflashboard()
{
yield return new WaitForSeconds (2f);
request = (HttpWebRequest)WebRequest.Create(url);
//request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
rankinginfo = sr.ReadToEnd();
string[] word = rankinginfo.Trim().Split(',');
//word[0]就是讀到的第一筆資料
}
}
新增,刪除,修改資料(要執行那一個功能,是根據連結到的php檔案是執行刪除的sql語法還是刪除或修改的sql語法)using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System.Net;
public class ButtonClick : MonoBehaviour {
{
public string url; //url是指要連結的php檔案位置,此範例為127.0.0.1/insert.php
void Update()
{
WWWForm form = new WWWForm ();
form.AddField ("score", score.ToString ()); //score是php檔案內的$_POST['score'],單引號內的變數
form.AddField ("groups", team_name); //groups是$_POST['groups'],單引號內的變數
for (int i = 0; i < DBcolumn.Length; i++)
{
form.AddField (DBcolumn[i], inputfield[i].text);
}
WWW www = new WWW (url, form);
StartCoroutine (updatesco (www));
}
IEnumerator (updatesco (WWW www){
yield return www;
}
}
沒有範例
public Camera mainCamera;
IEnumerator ScreenCapture() {
//在擷取畫面之前請等到所有的Camera都Render完
yield return new WaitForEndOfFrame();
Texture2D texture = new Texture2D((int)mainCamera.pixelWidth, (int)mainCamera.pixelHeight);
//擷取全部畫面的資訊
texture.ReadPixels(new Rect(0, 0, (int)mainCamera.pixelWidth, (int)mainCamera.pixelHeight),0,0, false);
texture.Apply();
}
螢幕擷取後,儲存圖片:
void SaveTextureToFile(Texture2D texture, string fileName) {
byte[] bytes = texture.EncodeToPNG();
string filePath = Application.dataPath + "/" + fileName + ".png";
using (FileStream fs = File.Open(filePath, FileMode.Create)) {
BinaryWriter binary = new BinaryWriter(fs);
binary.Write(bytes);
}
}
程式碼參考自 -> http://www.iverv.com/2014/04/unityscreenshot.html