【发布时间】:2023-01-29 20:36:14
【问题描述】:
我有一个简单的播放器移动脚本,但我遇到了以下错误“RenderBuffer”不包含“速度”的定义,我不知道如何修复它。
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting.Antlr3.Runtime.Tree;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private Rigidbody2D rb;
private BoxCollider2D coll;
private bool hasDoubleJumped = false;
[SerializeField] private float moveSpeed = 7f;
[SerializeField] private float jumpForce = 14f;
[SerializeField] private LayerMask jumpableGround;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
coll = GetComponent<BoxCollider2D>();
}
private void Update()
{
float dirX = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(dirX * moveSpeed, rb.velocity.y);
if (Input.GetButtonDown("Jump") && IsGrounded())
{
hasDoubleJumped = false;
rb.velocity = new Vector2(RenderBuffer.velocity.x, jumpForce);
}
else if (Input.GetButtonDown("Jump") && !hasDoubleJumped)
{
hasDoubleJumped = true;
rb.velocity = new Vector2(RenderBuffer.velocity.x, jumpForce);
}
}
private bool IsGrounded()
{
return Physics2D.BoxCast(coll.bounds.center, coll.bounds.size, 0f, Vector2.down, .1f, jumpableGround);
}
}
我试过改变一些东西,但它似乎并没有解决我的问题。
【问题讨论】:
标签: unity3d