繁体   English   中英

为什么会出现此错误:Assets\\Character2DController.cs(35,21): error CS0103: The name 'Physics2d' does not exist in the current context

[英]Why is this error appearing: Assets\Character2DController.cs(35,21): error CS0103: The name 'Physics2d' does not exist in the current context

所以对于上下文,我正在尝试制作角色的控制器,并且我正在学习 c# 所以,如果你们有更多关于 te 代码的提示,请告诉代码:

using UnityEngine;

public class Character2DController : MonoBehaviour
{
    public float MovementSpeed = 10;
    public float JumpForce;
    bool isGrounded;
    public Transform GroundCheck;
    public LayerMask groundLayer;

    private Rigidbody2D _rigidbody;

    private void Start()
    {
        _rigidbody = GetComponent<Rigidbody2D>();
       
    }

     void Update()
    {
        var movement = Input.GetAxis("Horizontal");
        transform.position  += new Vector3 (movement, 0 ,0) * Time.deltaTime * MovementSpeed;
 
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (isGrounded)
            {
            _rigidbody.velocity = Vector2.up * JumpForce;
            }
        }
    }
    private void FixedUpdate()
    {
       isGrounded = Physics2d.OverlapCircle(GroundCheck.position, 0.2f, groundLayer);

    }
}

Unity 为您提供了许多用于 2D 和 3D 的物理函数 API。

要访问 2D 函数,请使用 Physics2D 静态类,而不是 Physics2d。 要访问 3D 函数,请使用 Physics3D 静态类,而不是 Physics3d。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM