【发布时间】:2019-03-10 02:37:02
【问题描述】:
只有在单击鼠标左键后,我才试图让我的主摄像头在 Y 轴上缓慢向上移动。
这是我目前的代码。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class CameraPanUp : MonoBehaviour
{
public float speed = 5f;
public Transform target;
Vector3 offset;
// Start is called before the first frame update
void Start()
{
offset = transform.position - target.position;
}
// Update is called once per frame
void FixedUpdate()
{
Vector3 targetCamPos = target.position + offset;
transform.position = Vector3.Lerp(transform.position, targetCamPos, speed * Time.deltaTime);
if (Input.GetMouseButtonDown(0))
{
}
}
}
我不确定在上面的 if 语句中应该放什么。我之前尝试过使用transform.Translate,每次左键单击时它都会使相机以小幅度向上移动。这是为什么?任何帮助将不胜感激。
【问题讨论】:
-
改成
Input.GetMouseButton(0)只要按住鼠标按钮,相机就会向上移动
标签: unity3d