C# 为什么在使用断点时,脚本将继续运行并可以正常工作,但如果没有断点,脚本将无法正常工作?
它停在这一行,然后我点击continue,它进入了更新中的其余代码 但如果我没有在这条线上加一个断点,它就不起作用了。没有给出错误或异常,只是没有看到更新中的其余代码。 碰撞器停止接触后,在FixedUpdate上发生OnTiggerExit 更新每帧发生一次,而FixedUpdate在计时器上发生。所以这里的事情可能只是不同步。创建断点将确保帧停止,并且在执行此操作时,所有内容都可能对齐。 碰撞器停止接触后,在FixedUpdate上发生OnTiggerExitC# 为什么在使用断点时,脚本将继续运行并可以正常工作,但如果没有断点,脚本将无法正常工作?,c#,unity3d,C#,Unity3d,它停在这一行,然后我点击continue,它进入了更新中的其余代码 但如果我没有在这条线上加一个断点,它就不起作用了。没有给出错误或异常,只是没有看到更新中的其余代码。 碰撞器停止接触后,在FixedUpdate上发生OnTiggerExit 更新每帧发生一次,而FixedUpdate在计时器上发生。所以这里的事情可能只是不同步。创建断点将确保帧停止,并且在执行此操作时,所有内容都可能对齐。 碰撞器停止接触后,在FixedUpdate上发生OnTiggerExit 更新每帧发生一次,而Fixed
更新每帧发生一次,而FixedUpdate在计时器上发生。所以这里的事情可能只是不同步。创建断点将确保帧停止,并且在执行此操作时,所有内容都可能对齐。如何设置断点?一张屏幕截图,上面有你遵循的步骤?我发现了问题。如果我移动玩家的角色太快,它将无法计算足够好的距离,但一旦我移动玩家非常慢,它就会工作。我猜问题在于距离,因为在使用距离之前,它工作正常。请尝试将代码移动到
LateUpdate
。在所有Update
调用完成后调用它。我猜当您移动npc
的其他Update
方法时,可能会更改您试图依赖的某些值。用户输入后应该发生的事情应该放在LateUpdate
如何设置断点?一张屏幕截图,上面有你遵循的步骤?我发现了问题。如果我移动玩家的角色太快,它将无法计算足够好的距离,但一旦我移动玩家非常慢,它就会工作。我猜问题在于距离,因为在使用距离之前,它工作正常。请尝试将代码移动到LateUpdate
。在所有Update
调用完成后调用它。我猜当您移动npc
的其他Update
方法时,可能会更改您试图依赖的某些值。用户输入后应该发生的事情应该放在LateUpdate
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
public class SpaceshipCutscene : MonoBehaviour
{
public Transform player;
public Transform[] npcs;
public Transform console;
public Camera FPSCamera;
public Camera mainCamera;
public Animator[] anim;
public float rotationSpeed = 3f;
public float distanceFromConsole;
private bool moveNpc = false;
private float sp = 0f;
private float distance;
// Use this for initialization
void Start()
{
}
private void Update()
{
distance = Vector3.Distance(transform.position, npcs[0].transform.position);
if (moveNpc)
{
// Soldier 2 rotating and looking at player
Vector3 dir = player.position - npcs[0].position;
dir.y = 0; // keep the direction strictly horizontal
Quaternion rot = Quaternion.LookRotation(dir);
// slerp to the desired rotation over time
npcs[0].rotation = Quaternion.Slerp(npcs[0].rotation, rot, rotationSpeed * Time.deltaTime);
var dist = Vector3.Distance(npcs[1].position, console.position);
if (dist < distanceFromConsole)
{
sp += Time.deltaTime;
sp = Mathf.Clamp(sp, 0f, 1f);
anim[1].SetFloat("WalkingSpeed", sp);
}
Vector3 dirToComputer = console.transform.position - npcs[1].position;
dirToComputer.y = 0;
Quaternion rot1 = Quaternion.LookRotation(dirToComputer);
npcs[1].rotation = Quaternion.Slerp(npcs[1].rotation, rot1, rotationSpeed * Time.deltaTime);
}
}
private void OnTriggerExit(Collider other)
{
if (HoriDoorManager.doorLockState == false && distance < 5f)
{
if (other.gameObject.tag == "SpaceshipCutscene")
{
FPSCamera.enabled = false;
mainCamera.enabled = true;
moveNpc = true;
anim[0].SetBool("Aiming", true);
anim[1].SetBool("Walktouse", true);
}
}
}
}
FPSCamera.enabled = false;