简体   繁体   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

so for context I'm trying to make the controller of the character, and I'm learning c# so, if you guys have some more tips for te code, please tell code:所以对于上下文,我正在尝试制作角色的控制器,并且我正在学习 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 provides you lots of Physics function APIs for 2D and 3D. Unity 为您提供了许多用于 2D 和 3D 的物理函数 API。

To access the 2D functions use Physics2D static class, not Physics2d.要访问 2D 函数,请使用 Physics2D 静态类,而不是 Physics2d。 To access the 3D functions use Physics3D static class, not Physics3d.要访问 3D 函数,请使用 Physics3D 静态类,而不是 Physics3d。

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

相关问题 错误 CS0103:当前上下文中不存在名称“currentScreen”(CS0103) - Error CS0103: The name 'currentScreen' does not exist in the current context (CS0103) 错误 CS0103:当前上下文中不存在名称“_context” - Error CS0103: The name '_context' does not exist in the current context 错误CS0103当前上下文中不存在名称“图像” - Error CS0103 The name 'Image' does not exist in the current context Unity错误CS0103:当前上下文中不存在名称`&#39; - Unity error CS0103: The name `' does not exist in the current context 错误 CS0103: 当前上下文中不存在名称“ ” - error CS0103: The name ' ' does not exist in the current context 错误 CS0103:当前上下文中不存在名称“x” - error CS0103: The name 'x' does not exist in the current context 错误 CS0103:当前上下文中不存在名称“IsInRole” - ERROR CS0103: The name 'IsInRole' does not exist in the current context 错误CS0103:名称“ HttpClientFactory”在当前上下文中不存在 - error CS0103: The name `HttpClientFactory' does not exist in the current context 错误CS0103:名称“ TimeSpan”在当前上下文(CS0103)(testingProgram)中不存在? - Error CS0103: The name 'TimeSpan' does not exist in the current context (CS0103) (testingProgram)? 错误cs0103名称&#39;IEnumerator&#39;在当前上下文中不存在 - error cs0103 The Name 'IEnumerator' does not exist in the current context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM