多个错误消息C#脚本统一。需要一些帮助(开始编写脚本)

多个错误消息C#脚本统一。需要一些帮助(开始编写脚本),c#,unity3d,C#,Unity3d,我从现在起在团结工会工作了两天。我正在为2d精灵编写脚本。当我添加最后的元素时,脚本不再工作了。但我想让这一切顺利。是否有人可以查看错误消息,然后查看脚本以了解它的错误 错误1:(25,38):错误CS1503:参数#2'无法将float'表达式转换为'UnityEngine.Vector2'类型 错误2:(25,38):错误CS1502:“UnityEngine.Physics2D.OverlappeBox(UnityEngine.Vector2,UnityEngine.Vector2,flo

我从现在起在团结工会工作了两天。我正在为2d精灵编写脚本。当我添加最后的元素时,脚本不再工作了。但我想让这一切顺利。是否有人可以查看错误消息,然后查看脚本以了解它的错误

错误1:(25,38):错误CS1503:参数
#2'无法将
float'表达式转换为'UnityEngine.Vector2'类型

错误2:(25,38):错误CS1502:“UnityEngine.Physics2D.OverlappeBox(UnityEngine.Vector2,UnityEngine.Vector2,float)”的最佳重载方法匹配具有一些无效参数


脚本:

using UnityEngine;

using System.Collections;

public class PlayerController : MonoBehaviour
{

    public float speed = 5f;
    public float jumpSpeed = 8f;
    private float movement = 0f;
    private Rigidbody2D rigidBody;
    public Transform groundCheckPoint;
    public float groundCheckRadius;
    public LayerMask groundLayer;
    private bool isTouchingGround;


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


    void Update()
    {
        isTouchingGround = Physics2D.OverlapBox (groundCheckPoint.position, groundCheckRadius, groundLayer);
        movement = Input.GetAxis ("Horizontal");
        if (movement > 0f)
        {
            rigidBody.velocity = new Vector2 (movement * speed, rigidBody.velocity.y);
        }
        else if (movement < 0f)
        {
            rigidBody.velocity = new Vector2 (movement * speed, rigidBody.velocity.y);
        }
        else
        {
            rigidBody.velocity = new Vector2(0, rigidBody.velocity.y);
        }

        if (Input.GetButtonDown("Jump") && isTouchingGround)
        {
            rigidBody.velocity = new Vector2(rigidBody.velocity.x,jumpSpeed);
        }
    }
}
使用UnityEngine;
使用系统集合;
公共类玩家控制器:单行为
{
公共浮子速度=5f;
公共浮子跳跃速度=8f;
私人浮动移动=0f;
私有刚体2d刚体;
公共检查站;
公众浮标地面检查半径;
公共层屏蔽底层;
私人住宅区正在接触地面;
void Start()
{
刚体=GetComponent();
}
无效更新()
{
isTouchingGround=Physics2D.Overlapper(groundCheckPoint.position,groundCheckRadius,groundLayer);
移动=Input.GetAxis(“水平”);
如果(移动>0f)
{
rigidBody.velocity=新矢量2(运动*速度,rigidBody.velocity.y);
}
否则如果(移动<0f)
{
rigidBody.velocity=新矢量2(运动*速度,rigidBody.velocity.y);
}
其他的
{
rigidBody.velocity=新矢量2(0,rigidBody.velocity.y);
}
if(Input.GetButtonDown(“Jump”)&&isTouchGround)
{
rigidBody.velocity=新矢量2(rigidBody.velocity.x,跳跃速度);
}
}
}
如果您仍然想使用Overlappbox,这里是指向它的脚本API的链接(每当我遇到困难时,我都会亲自到这里):

另外,我会将玩家跳转的编码移到FixedUpdate函数,而不是Update函数。下面是我的代码,来自于我为一个游戏果酱制作的2D平台上的播放器控制器脚本。希望这有帮助

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed;
    public float jumpForce;
    private float moveInput;
    private Rigidbody2D rb;
    private bool facingRight = true;
    private bool isGrounded;
    public Transform groundCheck;
    public float checkedRadius;
    public LayerMask whatIsGround;
    private int extraJumps;


    private void Start()
    {
        extraJumps = 1;
        rb = GetComponent<Rigidbody2D>();

    }

    private void FixedUpdate()
    {
        isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkedRadius, whatIsGround);
        moveInput = Input.GetAxisRaw("Horizontal");

        rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);

        if (facingRight == false && moveInput > 0)
        {
            Flip();
        }
        else if (facingRight == true && moveInput < 0)
        {
            Flip();
        }
    }

    private void Update()
    {


        if (isGrounded == true)
        {
            extraJumps = 2;
        }
        if (Input.GetKeyDown(KeyCode.W) && extraJumps > 0)
        {
            rb.velocity = Vector2.up * jumpForce;
            extraJumps--;
        }
        else if (Input.GetKeyDown(KeyCode.W) && extraJumps == 0 && isGrounded == true)
        {
            rb.velocity = Vector2.up * jumpForce;
        }
    }

    void Flip()
    {
        facingRight = !facingRight;
        Vector3 Scaler = transform.localScale;
        Scaler.x *= -1;
        transform.localScale = Scaler;
    }
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类玩家控制器:单行为
{
公众浮标速度;
公共安全部队;
私有浮点输入;
私有刚体2d rb;
私有bool-facingRight=true;
私人学校停课;
公开审查;
公众浮动支票;
公共层码头;
私家车;
私有void Start()
{
外部跳跃=1;
rb=GetComponent();
}
私有void FixedUpdate()
{
IsGround=Physics2D.重叠圆(groundCheck.position,checkedRadius,whatIsGround);
moveInput=Input.GetAxisRaw(“水平”);
rb.velocity=新矢量2(移动输入*速度,rb.velocity.y);
if(facingRight==false&&moveInput>0)
{
翻转();
}
else if(facingRight==true&&moveInput<0)
{
翻转();
}
}
私有void更新()
{
如果(isGrounded==真)
{
外跳跃=2;
}
if(Input.GetKeyDown(KeyCode.W)和&extraJumps>0)
{
rb.速度=矢量2.向上*跳跃力;
额外跳跃--;
}
else if(Input.GetKeyDown(KeyCode.W)&&extraJumps==0&&isground==true)
{
rb.速度=矢量2.向上*跳跃力;
}
}
void Flip()
{
facingRight=!facingRight;
Vector3 Scaler=transform.localScale;
Scaler.x*=-1;
transform.localScale=Scaler;
}
}

您的意思是使用
Physics2D.OverlapCircle
而不是
Physics2D.OverlapBox
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed;
    public float jumpForce;
    private float moveInput;
    private Rigidbody2D rb;
    private bool facingRight = true;
    private bool isGrounded;
    public Transform groundCheck;
    public float checkedRadius;
    public LayerMask whatIsGround;
    private int extraJumps;


    private void Start()
    {
        extraJumps = 1;
        rb = GetComponent<Rigidbody2D>();

    }

    private void FixedUpdate()
    {
        isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkedRadius, whatIsGround);
        moveInput = Input.GetAxisRaw("Horizontal");

        rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);

        if (facingRight == false && moveInput > 0)
        {
            Flip();
        }
        else if (facingRight == true && moveInput < 0)
        {
            Flip();
        }
    }

    private void Update()
    {


        if (isGrounded == true)
        {
            extraJumps = 2;
        }
        if (Input.GetKeyDown(KeyCode.W) && extraJumps > 0)
        {
            rb.velocity = Vector2.up * jumpForce;
            extraJumps--;
        }
        else if (Input.GetKeyDown(KeyCode.W) && extraJumps == 0 && isGrounded == true)
        {
            rb.velocity = Vector2.up * jumpForce;
        }
    }

    void Flip()
    {
        facingRight = !facingRight;
        Vector3 Scaler = transform.localScale;
        Scaler.x *= -1;
        transform.localScale = Scaler;
    }
}