Skip to content

Instantly share code, notes, and snippets.

@TakashiYoshinaga
Last active September 19, 2017 08:30
Show Gist options
  • Save TakashiYoshinaga/ec7cfc423aeffd0797b723880064d496 to your computer and use it in GitHub Desktop.
Save TakashiYoshinaga/ec7cfc423aeffd0797b723880064d496 to your computer and use it in GitHub Desktop.
public void Update ()
{
_QuitOnConnectionErrors();
// The tracking state must be FrameTrackingState.Tracking in order to access the Frame.
if (Frame.TrackingState != FrameTrackingState.Tracking)
{
const int LOST_TRACKING_SLEEP_TIMEOUT = 15;
Screen.sleepTimeout = LOST_TRACKING_SLEEP_TIMEOUT;
return;
}
Screen.sleepTimeout = SleepTimeout.NeverSleep;
Frame.GetNewPlanes(ref m_newPlanes);
// Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them.
for (int i = 0; i < m_newPlanes.Count; i++)
{
// Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to
// the origin with an identity rotation since the mesh for our prefab is updated in Unity World
// coordinates.
GameObject planeObject = Instantiate(m_trackedPlanePrefab, Vector3.zero, Quaternion.identity,
transform);
planeObject.GetComponent<TrackedPlaneVisualizer>().SetTrackedPlane(m_newPlanes[i]);
// Apply a random color and grid rotation.
planeObject.GetComponent<Renderer>().material.SetColor("_GridColor", m_planeColors[Random.Range(0,
m_planeColors.Length - 1)]);
planeObject.GetComponent<Renderer>().material.SetFloat("_UvRotation", Random.Range(0.0f, 360.0f));
}
// m_searchingForPlaneUI.SetActive(showSearchingUI);
Touch touch;
if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
{
return;
}
//下記コードによりタップする度にCubeを生成して前え飛ばす。サイズとか勢いは適当
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = m_firstPersonCamera.transform.TransformPoint(0, 0, 0.5f);
cube.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
cube.AddComponent<Rigidbody>();
cube.GetComponent<Rigidbody>().AddForce(m_firstPersonCamera.transform.TransformDirection(0, 1f, 2f),ForceMode.Impulse);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment