包含此页的版本:
不含此页的版本:
检查碰撞当物理引擎检测到两个游戏对象的碰撞器接触或重叠时,当至少一个游戏对象具有刚体组件并且处于运动状态时,就会发生碰撞。更多信息
请参阅术语表并确保 LostCrypt 不存在允许您的角色移动到地图之外的错误。
查看游戏对象Environment/Character Bounds - Left.您可以看到它位于我们 2D 地图的左侧。它旨在保护玩家免于退出地图并掉入纹理中。让我们看看它是否达到了它的目的。
MainScene\_CharacterDoesNotFallIntoTextures在MovementTest.cs.WaitForSeconds(0.5f)跳跃之间可以更好地模拟用户行为。Character Bounds - Leftgame 对象。MovementTest.cs
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.SceneManagement;
public class MovementTest
{
const float _testTimeout = 20.0f;
private Transform _characterTransform;
[UnityTest]
public IEnumerator MainScene_CharacterDoesNotFallIntoTextures()
{
SceneManager.LoadScene("Assets/Scenes/Main.unity", LoadSceneMode.Single);
yield return waitForSceneLoad();
yield return GoLeft();
while (Time.timeSinceLevelLoad < _testTimeout)
{
yield return new WaitForSeconds(0.5f);
yield return Jump();
if (GetCurrentCharacterPosition().x < -75f && GetCurrentCharacterPosition().y < -10f)
{
Assert.Fail("Character escaped the map and fell into textures! :(");
}
}
}
private Vector3 GetCurrentCharacterPosition()
{
// Get Main character's Transform which is used to manipulate position.
if (_characterTransform == null)
{
_characterTransform = GameObject.Find("Sara Variant").transform;
}
return _characterTransform.position;
}
private IEnumerator Jump()
{
TestInputControl.Jump = true;
yield return null;
TestInputControl.Jump = false;
}
private IEnumerator GoLeft()
{
TestInputControl.MoveRight = false;
yield return null;
TestInputControl.MoveLeft = true;
}
private IEnumerator waitForSceneLoad()
{
while (SceneManager.GetActiveScene().buildIndex > 0)
{
yield return null;
}
}
}
我们的测试失败了,我们的一个示例 Unity 项目中存在一个错误。您将如何解决这个问题?有很多可能性,请继续尝试将其作为本次培训的一部分进行修复: