[英]Error CS0103: The name 'currentScreen' does not exist in the current context (CS0103)
[英]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.