質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
ARKit

ARKitは、iPhone/iPad向けのARアプリ用フレームワーク。iOS11以降に標準搭載されています。これを用いたARアプリは、特殊なデバイスがなくてもiPhone/iPadの単眼カメラを使用して動作することが可能です。

ビルド

ソースコードを単体で実行可能なソフトウェアへ変換する過程をビルド(build)と呼びます

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

iPhone

iPhoneとは、アップル社が開発・販売しているスマートフォンです。 同社のデジタルオーディオプレーヤーiPodの機能、電話機能、インターネットやメールなどのWeb通信機能の3つをドッキングした機器です。

Q&A

解決済

1回答

1234閲覧

unityのエラーがどうしてもわからない

airi_pumpkin

総合スコア30

ARKit

ARKitは、iPhone/iPad向けのARアプリ用フレームワーク。iOS11以降に標準搭載されています。これを用いたARアプリは、特殊なデバイスがなくてもiPhone/iPadの単眼カメラを使用して動作することが可能です。

ビルド

ソースコードを単体で実行可能なソフトウェアへ変換する過程をビルド(build)と呼びます

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

iPhone

iPhoneとは、アップル社が開発・販売しているスマートフォンです。 同社のデジタルオーディオプレーヤーiPodの機能、電話機能、インターネットやメールなどのWeb通信機能の3つをドッキングした機器です。

0グッド

0クリップ

投稿2019/09/07 08:37

unityでARKitを使いiPhoneへARアプリを作ろうとしているのですが、ビルドをしようとしたらいくつかエラーが出てしまいました。ネットでエラーを調べてもよくわかりませんでした。
unityのことはからっきしなのでどなたか分かる方がいらしたら教えていただきたいです。

エラー文
イメージ説明

記述したコード1

using System.Collections.Generic; using UnityEngine.EventSystems; namespace UnityEngine.XR.iOS { public class UnityARHitTestExample : MonoBehaviour { public Transform m_HitTransform; public float maxRayDistance = 30.0f; public LayerMask collisionLayer = 1 << 10; //ARKitPlane layer bool HitTestWithResultType (ARPoint point, ARHitTestResultType resultTypes) { List<ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface ().HitTest (point, resultTypes); if (hitResults.Count > 0) { foreach (var hitResult in hitResults) { Debug.Log ("Got hit!"); m_HitTransform.position = UnityARMatrixOps.GetPosition (hitResult.worldTransform); m_HitTransform.rotation = UnityARMatrixOps.GetRotation (hitResult.worldTransform); Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); return true; } } return false; } // Update is called once per frame void Update () { #if UNITY_EDITOR //we will only use this script on the editor side, though there is nothing that would prevent it from working on device if (Input.GetMouseButtonDown (0)) { Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition); RaycastHit hit; //we'll try to hit one of the plane collider gameobjects that were generated by the plugin //effectively similar to calling HitTest with ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent if (Physics.Raycast (ray, out hit, maxRayDistance, collisionLayer)) { //we're going to get the position from the contact point m_HitTransform.position = hit.point; Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z)); //and the rotation from the transform of the plane collider m_HitTransform.rotation = hit.transform.rotation; } } #else if (Input.touchCount > 0 && m_HitTransform != null && !IsPointerOverUIObject()) { var touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { var screenPosition = Camera.main.ScreenToViewportPoint(touch.position); ARPoint point = new ARPoint { x = screenPosition.x, y = screenPosition.y }; // prioritize reults types ARHitTestResultType[] resultTypes = { //ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingGeometry, ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, // if you want to use infinite planes use this: //ARHitTestResultType.ARHitTestResultTypeExistingPlane, //ARHitTestResultType.ARHitTestResultTypeEstimatedHorizontalPlane, //ARHitTestResultType.ARHitTestResultTypeEstimatedVerticalPlane, //ARHitTestResultType.ARHitTestResultTypeFeaturePoint }; foreach (ARHitTestResultType resultType in resultTypes) { if (HitTestWithResultType (point, resultType)) { return; } } private bool IsPointerOverUIObject() { PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current); eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y); List<RaycastResult> results = new List<RaycastResult>(); EventSystem.current.RaycastAll(eventDataCurrentPosition, results); return results.Count > 0; } } } #endif } } }

記述したコード2

using System.Collections; using System.Collections.Generic; using UnityEngine; public class WolfScript : MonoBehaviour { private Animation anim; private bool walkMode; // Start is called before the first frame update void Start() { anim = GetComponent<Animation>(); } // Update is called once per frame void Update() { if (walkMode) { transform.Translate(Vector3.forward * Time.deltaTime * (transform.localScale.x * .1f)); } } public void RunAction() { anim.Play("Wolf_Skeleton|Wolf_Run_Cycle_"); walkMode = false; } public void SeatAction() { anim.Play("Wolf_Skeleton|Wolf_seat_"); walkMode = false; } public void WalkAction() { anim.Play("Wolf_Skeleton|Wolf_Walk_cycle_"); walkMode = true; } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Update()の中でIsPointerOverUIObject()が定義されています。

蛇足ですが、#if ~ #else ~ #endifで条件に当てはまらない箇所はコンパイル時に無視されます(すなわち、書いていないのと同じように扱われます)。
エディタでの編集中にはエラーは出ないが、iOSへのビルド時にエラーが出たのはそのためです。
エラー内容自体は、普通にエラー文を読んで該当の行を見ればわかる内容なので、この点に注意しましょう。

投稿2019/09/07 09:04

編集2019/09/07 09:09
fiveHundred

総合スコア9774

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

airi_pumpkin

2019/09/07 09:33

無事ビルドできました! unityだけでなくc#も勉強しなくてはですね... 解答していただきありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問