【发布时间】:2019-01-23 23:17:00
【问题描述】:
我现在正在关注本教程:https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial/moving-camera?playlist=17141
我已经设法实现了一个第三人称相机视图按钮,但我无法弄清楚如何为第一人称相机视图做同样的事情。下面是我附加到主摄像头的摄像头控制脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameraControls : MonoBehaviour
{
public GameObject player;
private Vector3 offset;
public bool thirdPerson;
public bool firstPerson;
void OnGUI()
{
// 3rd person camera view
if (GUI.Button(new Rect(20, 50, 140, 40), "3rd Person Camera"))
{
thirdPerson = true;
}
// 1st person camera view
if (GUI.Button(new Rect(20, 110, 140, 40), "1st Person Camera"))
{
firstPerson = false;
}
}
// 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 (thirdPerson == true)
{
transform.position = player.transform.position + offset;
}
}
}
【问题讨论】:
标签: c# object unity3d button camera