Restructure animations
This commit is contained in:
@@ -104,6 +104,7 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
speed: 400
|
||||
isPlayer1: 1
|
||||
move: {fileID: -944628639613478452, guid: 6cbaae0ad99590d468c8b501c0452c36, type: 3}
|
||||
--- !u!60 &6715754573185558080
|
||||
PolygonCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -2126,6 +2126,10 @@ PrefabInstance:
|
||||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 946501248446145305, guid: 603e313b1bcbb4e7ab65d3ec701ce789, type: 3}
|
||||
propertyPath: move.m_Name
|
||||
value: Move
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2899264478719472934, guid: 603e313b1bcbb4e7ab65d3ec701ce789, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: -8
|
||||
|
||||
@@ -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