360度動画を切り替えたい
ここに質問の内容を詳しく書いてください。
unityで天球儀イメージをHMDに写してコンテンツを作ろうとしていて、360度動画を使って切り替えて別の動画へ移行したいのですが、うまくキー入力を使ってシーン移行することができません
HMDに写す作業として、空のgameobject(94)にVideoplayerスクリプトを入れ、そこにテクスチャーをはり、materialをskybox/paranomicにして写しています
発生している問題・エラーメッセージ
MissingComponentException: There is no 'Renderer' attached to the "GameObject94" game object, but a script is trying to access it. You probably need to add a Renderer to the game object "GameObject94". Or your script needs to check if the component is attached before using it. UnityEngine.Renderer.set_sharedMaterial (UnityEngine.Material value) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Graphics/GraphicsRenderers.bindings.cs:140) test.Update () (at Assets/test.cs:28) IndexOutOfRangeException: Index was outside the bounds of the array. test.Update () (at Assets/test.cs:28)
該当のソースコード
using UnityEngine; using System.Collections; public class test : MonoBehaviour { public Material[] _material; // 割り当てるマテリアル. private int i; // Use this for initialization void Start() { i = 0; } // Update is called once per frame void Update() { if (Input.GetKeyUp(KeyCode.Space)) { i++; if (i == 3) { i = 0; } this.GetComponent<Renderer>().sharedMaterial = _material[i]; } } }
### 試したこと ここに問題に対して試したことを記載してください。 ### 補足情報(FW/ツールのバージョンなど) ここにより詳細な情報を記載してください。
多分「シーン移行時のデータ消去・置き換えのタイミングでthis.GetComponent<Renderer>()している為にコンポーネントが見付からない」んだと思います。
「シーン移行しない」か「シーン移行が完了してからthis.GetComponent<Renderer>()〜の行を実行するようにする」と動くと思います。
あなたの回答
tips
プレビュー