有人能帮我解决这个脚本的问题吗

问题描述 投票:0回答:0

这是我用 c# 编写的代码。它是我在 unity 引擎中的乒乓游戏脚本:

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

public class ballBounce : MonoBehaviour
{
    public ballMovement BallMovement;

    private void Bounce(Collision2D collision);
    {
        Vector3 ballposition = transform.position;
        Vector3 racketPosition = collision.transform.position;
        float racketHeight = collision.collider.bounds.size.y;

        float positionX;
        if(collision.gameObject.name = "Player1"){
            positionX = 1;
        }
        
        else{
            positionX = -1
        }

        
        float positionY = (ballposition.y - racketPosition.y) / racketHeight;

        ballMovement.IncreaseHitCounter();
        ballMovement.Moveball(new Vector2(positionX, positionY));
    }
    
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if(collision.gameObject.name == "Player1") || collision.gameObject.name == "player2"
        {
            Bounce(collision);
        }
    }
}

它没有做任何事情,只是给我错误:

error CS01022:类型或命名空间定义,或文件结尾预期

c# unity3d
© www.soinside.com 2019 - 2024. All rights reserved.