这是我用 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:类型或命名空间定义,或文件结尾预期