blob: a0466ce40ddb0e01c0055bff531f649f1e11042a (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
using UnityEngine;
namespace Rewired.Demos;
[AddComponentMenu("")]
[RequireComponent(typeof(CharacterController))]
public class PressAnyButtonToJoinExample_GamePlayer : MonoBehaviour
{
public int playerId;
public float moveSpeed = 3f;
public float bulletSpeed = 15f;
public GameObject bulletPrefab;
private CharacterController cc;
private Vector3 moveVector;
private bool fire;
private Player player
{
get
{
if (!ReInput.isReady)
{
return null;
}
return ReInput.players.GetPlayer(playerId);
}
}
private void OnEnable()
{
cc = GetComponent<CharacterController>();
}
private void Update()
{
if (ReInput.isReady && player != null)
{
GetInput();
ProcessInput();
}
}
private void GetInput()
{
moveVector.x = player.GetAxis("Move Horizontal");
moveVector.y = player.GetAxis("Move Vertical");
fire = player.GetButtonDown("Fire");
}
private void ProcessInput()
{
if (moveVector.x != 0f || moveVector.y != 0f)
{
cc.Move(moveVector * moveSpeed * Time.deltaTime);
}
if (fire)
{
Object.Instantiate(bulletPrefab, base.transform.position + base.transform.right, base.transform.rotation).GetComponent<Rigidbody>().AddForce(base.transform.right * bulletSpeed, ForceMode.VelocityChange);
}
}
}
|