blob: 2e3ec7b50a5f1c4fd8967739a013b302505cf1e7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField] private List<Rigidbody2D> segments;
[SerializeField] private float sensitivity;
private void Update()
{
if (Input.GetKey(KeyCode.D))
{
segments[0].AddForceAtPosition(Vector2.right * sensitivity, (Vector2)segments[0].transform.position - Vector2.up * 0.5f);
}
else if (Input.GetKey(KeyCode.A))
{
segments[0].AddForceAtPosition(Vector2.left * sensitivity, (Vector2)segments[0].transform.position - Vector2.up * 0.5f);
}
if (Input.GetKey(KeyCode.L))
{
segments[1].AddForceAtPosition(Vector2.right * sensitivity, (Vector2)segments[1].transform.position + Vector2.up * 0.5f);
}
else if (Input.GetKey(KeyCode.J))
{
segments[1].AddForceAtPosition(Vector2.left * sensitivity, (Vector2)segments[1].transform.position + Vector2.up * 0.5f);
}
if (Input.GetKey(KeyCode.RightArrow))
{
segments[2].AddForceAtPosition(Vector2.right * sensitivity, (Vector2)segments[2].transform.position + Vector2.up * 0.5f);
}
else if (Input.GetKey(KeyCode.LeftArrow))
{
segments[2].AddForceAtPosition(Vector2.left * sensitivity, (Vector2)segments[2].transform.position + Vector2.up * 0.5f);
}
}
}
|