Restructure animations
This commit is contained in:
@@ -6,18 +6,37 @@ public class PongPaddleBehavior : MonoBehaviour
|
||||
public float speed = 5f;
|
||||
public bool isPlayer1 = true;
|
||||
|
||||
private InputAction move;
|
||||
[SerializeField] private InputActionAsset move;
|
||||
private Rigidbody2D rb;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
move = isPlayer1 ? InputSystem.actions.FindAction("Player 1 Move") : InputSystem.actions.FindAction("Player 2 Move");
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
float direction = move.ReadValue<Vector2>().y;
|
||||
if (!isPlayer1)
|
||||
{
|
||||
Transform ball = FindFirstObjectByType<PongBallBehavior>().transform;
|
||||
|
||||
RaycastHit2D[] hits = Physics2D.RaycastAll(ball.position, ball.GetComponent<Rigidbody2D>().linearVelocity, Mathf.Infinity, LayerMask.GetMask("Pong Goal"));
|
||||
Debug.DrawRay(ball.position, ball.GetComponent<Rigidbody2D>().linearVelocity * 1000f, Color.red);
|
||||
|
||||
foreach(RaycastHit2D hit in hits)
|
||||
{
|
||||
if (hit.collider.gameObject.CompareTag("Pong Goal"))
|
||||
{
|
||||
print("Hit");
|
||||
float dir = transform.position.y - hit.point.y > 0 ? 1 : -1;
|
||||
|
||||
rb.linearVelocityY = dir * speed * Time.fixedDeltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
float direction = move.FindAction("Move").ReadValue<Vector2>().y;
|
||||
if (transform.position.y >= 4 && direction > 0 || transform.position.y <= -4 && direction < 0)
|
||||
{
|
||||
direction = 0;
|
||||
|
||||
Reference in New Issue
Block a user