为什么动画会闪烁,为什么使用其他动画后会变得更糟糕?
代码可能会有帮助,告诉我如果需要,我需要提供什么其他代码
using UnityEngine;
using UnityEngine.InputSystem;
using System.Collections;
public class OfficeTraveler : MonoBehaviour
{
//输入参考
[Header("Input References")]
public InputActionReference clickAction;
public InputActionReference mousePositionAction;
//设置
[Header("Settings")]
public float reachDistance = 300f;
//玩家动画
public Animator playerAnimator;
//是否正在旅行
private bool isTraveling = false;
private void Start()
{
clickAction.action.Enable();
clickAction.action.performed += OnClick;
mousePositionAction.action.Enable();
}
private void OnClick(InputAction.CallbackContext context)
{
if (isTraveling) return;
//鼠标位置
Vector2 mousePos = mousePositionAction.action.ReadValue<Vector2>();
Ray ray = Camera.main.ScreenPointToRay(mousePos);
//是否击中目标
if (Physics.Raycast(ray, out RaycastHit hit, reachDistance))
{
//击中目标
VentInteractable clickedVent = hit.collider.GetComponent<VentInteractable>();
if (clickedVent != null && clickedVent.destinationOffice != null)
{
StartCoroutine(TravelRoutine(clickedVent));
}
//击中错误室表
ErrorRoomTablet clickedTablet = hit.collider.GetComponent<ErrorRoomTablet>();
if (clickedTablet != null && !clickedTablet.isOpen)
{
clickedTablet.OpenTabletMenu();
}
}
}
private IEnumerator TravelRoutine(VentInteractable vent)
{
isTraveling = true;
//是否有物理动画
if (vent.ventAnimator != null && !string.IsNullOrEmpty(vent.ventOpenTrigger))
{
vent.ventAnimator.SetTrigger(vent.ventOpenTrigger);
}
//是否有玩家动画
if (playerAnimator != null && !string.IsNullOrEmpty(vent.cameraTrigger))
{
playerAnimator.enabled = true;
yield return null;
playerAnimator.SetTrigger(vent.cameraTrigger);
}
yield return new WaitForSeconds(vent.waitTime);
//移动到目的地
transform.position = vent.destinationOffice.position;
RoomViewSettings roomData = vent.destinationOffice.GetComponent<RoomViewSettings>();
//是否有房间数据
if (roomData != null)
{
Look lookScript = FindAnyObjectByType<Look>();
if (lookScript != null) lookScript.LoadRoomBlueprint(roomData);
}
//禁用玩家动画
if (playerAnimator != null)
{
playerAnimator.enabled = false;
}
isTraveling = false;
}
private void OnDestroy()
{
clickAction.action.performed -= OnClick;
}
}
using UnityEngine;
public class VentInteractable : MonoBehaviour
{
//目的地
[Header("Where to Go")]
public Transform destinationOffice;
//摄像机过渡
[Header("Camera Transition")]
public string cameraTrigger = "VentTravel";
//等待时间
public float waitTime = 1.0f;
//物理动画
[Header("Physical Vent Animation")]
public Animator ventAnimator;
//开启物理动画
public string ventOpenTrigger = "OpenVent";
}
评论 (0)