我正在尝试创建一个相机工具,允许相机围绕播放器旋转,然后在不再按住箭头键后重置其位置。但是当我试着
时using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CompleteCameraController : MonoBehaviour {
public Transform Player;
public float rotationSpeed = 10f;
public Vector3 offset;
private void Update()
{
if (Input.GetKey(KeyCode.LeftArrow)){
transform.RotateAround(Player.transform.position, Vector3.down, Time.deltaTime * 25);
}
if (Input.GetKey(KeyCode.RightArrow))
{
transform.RotateAround(Player.transform.position, Vector3.up, Time.deltaTime * 25);
}
if (Input.GetKey(KeyCode.UpArrow))
{
transform.RotateAround(Player.transform.position, Vector3.left, Time.deltaTime * 25);
}
if ((Player != null) && Input.GetKey(KeyCode.DownArrow))
{
transform.RotateAround(Player.transform.position, Vector3.right, Time.deltaTime * 25);
}
if (Input.GetKey(KeyCode.LeftArrow !=null))
{
transform.LookAt(Player.transform);
}
}
void LateUpdate()
{
Vector3 desiredPosition = Player.position + offset;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, rotationSpeed * Time.deltaTime);
transform.position = smoothedPosition;
}
}
答案 0 :(得分:1)
你可能错在这里:
public async Task<PartialViewResult> GetStudent(int? id)
{
List<SchoolDto> schools;
StudentDto student;
using (var uow = UnitOfWorkManager.Begin(TransactionScopeOption.Suppress))
{
// Repository 1 (Database 1)
student = await _studentAppService.GetStudentForEdit(new NullableIdDto { Id = id });
uow.Complete();
}
using (var uow = UnitOfWorkManager.Begin(TransactionScopeOption.Suppress))
{
// Repository 2 (Database 2)
schools = await _schoolAppService.GetSchoolList();
uow.Complete();
}
// ...
}
不清楚为什么你有if (Input.GetKey(KeyCode.LeftArrow !=null))
部分,删除它,你应该没事
答案 1 :(得分:1)
问题在于
if (Input.GetKey(KeyCode.LeftArrow !=null))
您正在将KeyCode.LeftArrow
与null
进行比较,但这不起作用,因为它是枚举。我认为你可以安全地删除!=null
部分,你会没事的。
在您发表评论后,我认为您需要执行以下操作:
if ( !Input.GetKey(KeyCode.LeftArrow))
{
transform.LookAt(Player.transform);
}