27 lines
791 B
C#
27 lines
791 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PaddleBouncer : MonoBehaviour
|
|
{
|
|
void OnTriggerEnter(Collider other)
|
|
{
|
|
var ballMovement = other.GetComponent<BallMovement>();
|
|
if (ballMovement != null){
|
|
var ballPos = other.transform.position;
|
|
var centerOffset = ballPos.x - this.transform.position.x;
|
|
var relOffset = (centerOffset / this.GetComponent<Collider>().bounds.size.x);
|
|
var bouceVector = new Vector2(-relOffset,1);
|
|
ballMovement.BounceTo(bouceVector.normalized);
|
|
return;
|
|
}
|
|
|
|
var powerup = other.GetComponent<Powerup>();
|
|
if (powerup != null)
|
|
{
|
|
powerup.Activate();
|
|
return;
|
|
}
|
|
}
|
|
}
|