我会尽力帮助你解决这个问题。
首先,我们需要分析一下你的代码和输入设置。你的摄像机脚本和放置对象脚本看起来都很正常。但是,你的输入设置可能存在问题。
从你的截图中可以看出,你的输入设置是使用 WASD 键和鼠标来控制摄像机和放置对象。然而,在你的摄像机脚本中,你使用了 InputAction.CallbackContext 来读取输入值,但是你没有检查输入值是否有效。
在你的放置对象脚本中,你使用了 InputAction.CallbackContext 来读取鼠标位置,但是你没有检查鼠标是否在放置区域内。
因此,我建议你检查你的输入设置和脚本中的输入值是否有效。另外,你可以尝试使用 Debug.Log 来打印出输入值和鼠标位置,以便于你调试问题。
此外,你的放置对象脚本中,有一个问题。你的 Payment 方法中,switch 语句中,你对每种类型的 mana 都进行了减少。但是,你没有检查 mana 是否足够减少。
因此,我建议你检查你的 Payment 方法中,是否有足够的 mana 来减少。
最后,我建议你尝试使用 Debug.Log 来打印出你的放置对象脚本中的变量值,以便于你调试问题。
这里是我的建议的代码:
摄像机脚本:
public class MoveCam : MonoBehaviour
{
// ...
public void Move(InputAction.CallbackContext ctx)
{
if (ctx.ReadValue<Vector2>() != Vector2.zero)
{
_moveInput = ctx.ReadValue<Vector2>();
}
}
public void EdgeMove(InputAction.CallbackContext ctx)
{
// ...
}
}
放置对象脚本:
public class Placement : MonoBehaviour
{
// ...
private void Update()
{
// ...
if (bloking.Count != 0 && playerMana1 - manaAmount1 <= 0 && playerMana2 - manaAmount2 <= 0 && playerMana3 - manaAmount3 <= 0)
{
plassable = false;
placementMat.SetColor("Color", Color.red);
}
else
{
plassable = true;
placementMat.SetColor("Color", Color.green);
}
}
public void Place(InputAction.CallbackContext ctx)
{
if (plassable)
{
Debug.Log("放置对象");
Instantiate(batiment, position);
Payment();
gameObject.SetActive(false);
}
}
private void Payment()
{
if (costMana1 != TypeMana.None)
{
if (player.air_mana >= manaAmount1)
{
player.air_mana -= manaAmount1;
}
else
{
Debug.Log("空气 mana 不足够");
}
}
if (costMana2 != TypeMana.None)
{
if (player.eau_mana >= manaAmount2)
{
player.eau_mana -= manaAmount2;
}
else
{
Debug.Log("水 mana 不足够");
}
}
if (costMana3 != TypeMana.None)
{
if (player.feu_mana >= manaAmount3)
{
player.feu_mana -= manaAmount3;
}
else
{
Debug.Log("火 mana 不足够");
}
}
}
}
希望我的建议能够帮助你解决问题。
评论 (0)