如何在每个房间中放置单独的摄像机以显示播放器的位置?

时间:2019-01-29 23:38:05

标签: c# object unity3d camera

我已经实现了玩家移动以及三个不同的房间。我了解如何创建第一人称和第三人称摄影机,但是如何制作三个不同的摄影机视图来跟踪每个房间的玩家?更具体地说,单击相应的按钮后,是否可以放大每个房间?

enter image description here

到目前为止,我使用此代码将一个单独的脚本附加到主摄像头(我知道这可能不是最有效的方法,但是我只是在学习Unity和C#,所以这对我来说最有意义):

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

public class cameraControls : MonoBehaviour
{
    public GameObject player;
    //private Vector3 offset;
    public bool greenRoom;
    public bool blueRoom;
    public bool purpleRoom;


    void OnGUI()
    {
        // Room 1 (Green room)
        if (GUI.Button(new Rect(20, 50, 140, 40), "Green Room Camera"))
        {
            greenRoom = true;
            blueRoom = false;
            purpleRoom = false;
        }

        // Room 2 (Blue room)
        if (GUI.Button(new Rect(20, 110, 140, 40), "Blue Room Camera"))
        {
            blueRoom = true;
            greenRoom = false;
            purpleRoom = false;
        }

        // Room 3 (Purple room)
        if (GUI.Button(new Rect(20, 110, 140, 40), "Purple Room Camera"))
        {
            blueRoom = false;
            greenRoom = false;
            purpleRoom = true;
        }
    }

    // Start is called before the first frame update
    void Start()
    {
        //offset = transform.position - player.transform.position;
    }

    // Update is called once per frame
    void Update()
    {
        if (greenRoom == true && blueRoom == false && purpleRoom == false)
        {
        }

        if (blueRoom == true && greenRoom == false && purpleRoom == false)
        {
        }

        if (purpleRoom == true && blueRoom == false && greenRoom == false)
        {
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我发现通过使用transform.LookAt可以设置特定的坐标!