2017-06-20 18 views
0

通常、新しいエンジンではシンプルなグラフィックス(通常は四角形/長方形)を使ってゾンビシューティングゲームをトップダウンしようとしていますが、これは現在Unityでやろうとしています。Unityのカメラ境界のちょうど外側にゾンビを召喚する

私は私が持っているポイントに持っている:産卵とプレイヤー向かう

  • ゾンビ(WASD /矢印キーと マウスを介して制御されると)新芽

    • プレーヤー
    • 死滅させることができるゾンビ(一度すべてのゾンビは死んでいる、別の 波スポーン)

    しかし、現在、仕方が、私はSPそれらを生むようですあまりにも離れすぎてプレイヤーから遠ざかります。私は正射投影カメラを使用しています。

    コード:

    using System.Collections; 
    using System.Collections.Generic; 
    using UnityEngine; 
    
    public class ZombieSpawner : MonoBehaviour { 
        private int waveNumber = 0; 
        public int enemiesAmount = 0; 
        public GameObject zombie; 
        public Camera cam; 
        // Use this for initialization 
        void Start() { 
         cam = Camera.main; 
         enemiesAmount = 0; 
        } 
    
    // Update is called once per frame 
    void Update() { 
         float height = 2f * cam.orthographicSize; 
         float width = height * cam.aspect; 
         if (enemiesAmount==0) { 
          waveNumber++; 
          for (int i = 0; i < waveNumber; i++) { 
           Instantiate(zombie, new Vector3(cam.transform.position.x + Random.Range(-width, width),3,cam.transform.position.z+height+Random.Range(10,30)),Quaternion.identity); 
           enemiesAmount++; 
          } 
         } 
        } 
    } 
    
  • 答えて

    3

    あなたは彼らがちょうどカメラビューの外にゾンビを起動したい場合は、正射投影サイズを掛けないでください。

    float height = cam.orthographicSize; // now zombies spawn od camera view border 
    float height = cam.orthographicSize + 1 // now they spawn just outside 
    
    小さな変更It'a

    、しかし、あなたはまた、幅を設定することができます:1つ左のゾンビがある場合は別の波を起動し、ゲームのペースがどのように変化したかを確認するために

    float width = cam.orthographicSize * cam.aspect + 1; 
    

    てみてください。)

    関連する問題