2017-09-21 6 views
1

私はUnity3Dの初心者であり、ゲーム開発に関連しています。最近、HoloLensで実装するために簡単なプログラムを作成しようとしています。目標は、カメラが動く方向に動く3Dテキスト(「_テキスト」)を、本当にうまく動かすことです。しかし、私が(HoloLensで)(+/-)90度で頭を動かすと、私はテキストに直面していないので、テキストを読むことができません。誰かが私を助けることができれば感謝します。 :)Unityでカメラを使った3Dテキストの回転

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 

public class TextManager : MonoBehaviour { 

    public GameObject _text; 
    public TextMesh _startText; 

    // Use this for initialization 
    void Start() { 
     if (_text == null) _text = GameObject.Find("StartText"); 
     if (_startText == null) _startText = GameObject.Find("StartText").GetComponent<TextMesh>(); 
    } 

    // Update is called once per frame 
    void Update() { 

     if (_text.activeSelf) 
     { 
      var camPos = Camera.main.transform.position + Camera.main.transform.forward; 
      _text.transform.position = camPos; 
      _text.transform.localScale = Vector3.one * 0.025f;    
     } 

     else 
     { 
      Debug.Log("deactive _startText"); 
     } 

    } 
} 

答えて

1

看板動作を取得するには(テキストは常にカメラに見ている)あなたがテキストに変更されたカメラの回転を適用する必要がも同様にメッシュ:

_text.transform.rotation = Camera.main.transform.rotation; 

以上を取得するには新しくなった3D体験では、カメラが後ろを回るときにテキストを180°反転させるだけで、全体の向きを変えないと便利な場合があります。これを達成するには:

 Vector3 objectNormal = _text.rotation * Vector3.forward; 
     Vector3 cameraToText = _text.transform.position - Camera.main.transform.position; 
     float f = Vector3.Dot (objectNormal, cameraToText); 
     if (f < 0f) 
     { 
      _text.Rotate (0f, 180f, 0f); 
     } 
関連する問題