public virtual void RaycastHit(BallPhysics ball, RaycastHit hitInfo) { if (surfaceType.consideredForBounces) { ball.currentBounces++; } ball.velocity = Vector3.Reflect(ball.velocity, hitInfo.normal) * surfaceType.dampening; if (/*ball.currentBounces >= ball.ballType.bouncesUntilRespawn || */ ball.velocity.magnitude <= ball.ballType.minVelocityToRespawn) { ball.ToggleRenderer(false); ball.stopped = true; //Debug.Log("Ball DESTROYED after " + ball.ballType.bouncesUntilRespawn.ToString()); //TODO: Handle ball spawning if (!GameManager.Instance.gameOver) { StartCoroutine(GameManager.Instance.ballSpawner.WaitBeforeBallSpawn(GameManager.Instance.ballSpawner.spawnTime)); } } if (surfaceType.effectCollection != null) { if (PhotonNetwork.IsConnected) { photonView.RPC(nameof(PlayBounceEffect), RpcTarget.All, hitInfo.point); } else { PlayBounceEffect(hitInfo.point); } } }
public void SpawnBall() { Vector3 spawnDirection = GameManager.Instance.ballSpawner.spawnDirection; Vector3 ballSpawnVelocity = (player == PlayerNumber.Top ? spawnDirection : new Vector3(-spawnDirection.x, spawnDirection.y, -spawnDirection.z)) * GameManager.Instance.ballSpawner.spawnSpeed; if (GameManager.Instance.ballSpawner.currentBall == null) { GameManager.Instance.ballSpawner.currentBall = Instantiate(GameManager.Instance.ballSpawner.regularBallPrefab, transform.position, Quaternion.identity); } else { BallPhysics ball = GameManager.Instance.ballSpawner.currentBall.GetComponent <BallPhysics>(); ball.ToggleRenderer(true); ball.stopped = false; } GameManager.Instance.ballSpawner.lastPlayerDirectionSpawn = player; var ballPhysics = GameManager.Instance.ballSpawner.currentBall.GetComponent <BallPhysics>(); ballPhysics.canDamage = false; ballPhysics.velocity = ballSpawnVelocity; if (ballStatus) { ballStatus.OnApply(ballPhysics); } AudioManager.instance.PlaySound(GameManager.Instance.ballSpawner.spawnAudio, false, .1f); }
public void DestroyCurrentBall() { //Destroy(currentBall); BallPhysics ball = currentBall.GetComponent <BallPhysics>(); ball.ToggleRenderer(false); ball.stopped = true; //canSpawn = false; }