2 using System.Collections;
3 using System.Collections.Generic;
7 public class PlayerController : MonoBehaviour
9 [SerializeField] private List<Rigidbody2D> segments;
10 [SerializeField] private float sensitivity;
12 [SerializeField] private Rigidbody2D ballPrefab;
13 [SerializeField] private float ballSpeed;
17 if (Input.GetKey(KeyCode.D))
19 segments[0].AddForceAtPosition(Vector2.right * sensitivity, (Vector2)segments[0].transform.position - Vector2.up * 0.5f);
21 else if (Input.GetKey(KeyCode.A))
23 segments[0].AddForceAtPosition(Vector2.left * sensitivity, (Vector2)segments[0].transform.position - Vector2.up * 0.5f);
26 if (Input.GetKey(KeyCode.L))
28 segments[1].AddForceAtPosition(Vector2.right * sensitivity, (Vector2)segments[1].transform.position + Vector2.up * 0.5f);
30 else if (Input.GetKey(KeyCode.J))
32 segments[1].AddForceAtPosition(Vector2.left * sensitivity, (Vector2)segments[1].transform.position + Vector2.up * 0.5f);
35 if (Input.GetKey(KeyCode.RightArrow))
37 segments[2].AddForceAtPosition(Vector2.right * sensitivity, (Vector2)segments[2].transform.position + Vector2.up * 0.5f);
39 else if (Input.GetKey(KeyCode.LeftArrow))
41 segments[2].AddForceAtPosition(Vector2.left * sensitivity, (Vector2)segments[2].transform.position + Vector2.up * 0.5f);
44 if (Input.GetKeyDown(KeyCode.Space))
46 var ball = Instantiate(ballPrefab);
47 ball.transform.position = segments.Last().position;
48 ball.AddForce((Vector2.right + Vector2.up) * ballSpeed);