我试图让我的角色在 unity2D 中跳跃,跳跃本身有效,但我无法正确检查我的玩家是否接触地面。 我在统一控制台中收到 2 个错误。
第一个: Physics2D 不包含 OverLapArea 的防御。
第二个错误: Vector2 不包含带 3 个参数的构造函数。
(我也为我的英语不好道歉,这不是我的母语)
脚本:
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
public class jump : MonoBehaviour
{
public bool IsGrounded;
public LayerMask platfomLayer;
public Rigidbody2D rb2D ;
// Start is called before the first frame update
void Start()
{
rb2D = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
IsGrounded = Physics2D.OverLapArea (new Vector2(transform.position.x - 0.5f, transform.position.x - 0.5f),
new Vector2(transform.position.x + 0.5f, transform.position.y - 0, 51f),platfomLayer);
{
if (Input.GetKeyDown("space") && IsGrounded) rb2D.AddForce(transform.up * 2000f);
}
}
}
答案 0 :(得分:0)
两个错误都是正确的。
OverLapArea 拼写正确但大写错误。 Unity 引用区分大小写。
您确实在尝试将 3 个值传递到新的 Vector2 中。仔细查看您传递给第二个新 Vector2 值的内容。括号内有三个用逗号分隔的值。你好像把“0.5f”打错了“0, 51f”