summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/Rewired.Demos/EightPlayersExample_Player.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-19 16:05:58 +0800
committerchai <215380520@qq.com>2024-05-19 16:05:58 +0800
commit8e13e7e2874adc8982e16d1d2ed2e28d7480b45f (patch)
tree63ef85c460288891f5a593d69afeca16cba050b3 /Thronefall_1_57/Decompile/Rewired.Demos/EightPlayersExample_Player.cs
parentc5f145786f4c6d2fe4bea831dfc16e52228920a5 (diff)
+1.57
Diffstat (limited to 'Thronefall_1_57/Decompile/Rewired.Demos/EightPlayersExample_Player.cs')
-rw-r--r--Thronefall_1_57/Decompile/Rewired.Demos/EightPlayersExample_Player.cs71
1 files changed, 71 insertions, 0 deletions
diff --git a/Thronefall_1_57/Decompile/Rewired.Demos/EightPlayersExample_Player.cs b/Thronefall_1_57/Decompile/Rewired.Demos/EightPlayersExample_Player.cs
new file mode 100644
index 0000000..0ce56e1
--- /dev/null
+++ b/Thronefall_1_57/Decompile/Rewired.Demos/EightPlayersExample_Player.cs
@@ -0,0 +1,71 @@
+using System;
+using UnityEngine;
+
+namespace Rewired.Demos;
+
+[AddComponentMenu("")]
+[RequireComponent(typeof(CharacterController))]
+public class EightPlayersExample_Player : MonoBehaviour
+{
+ public int playerId;
+
+ public float moveSpeed = 3f;
+
+ public float bulletSpeed = 15f;
+
+ public GameObject bulletPrefab;
+
+ private Player player;
+
+ private CharacterController cc;
+
+ private Vector3 moveVector;
+
+ private bool fire;
+
+ [NonSerialized]
+ private bool initialized;
+
+ private void Awake()
+ {
+ cc = GetComponent<CharacterController>();
+ }
+
+ private void Initialize()
+ {
+ player = ReInput.players.GetPlayer(playerId);
+ initialized = true;
+ }
+
+ private void Update()
+ {
+ if (ReInput.isReady)
+ {
+ if (!initialized)
+ {
+ Initialize();
+ }
+ 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)
+ {
+ UnityEngine.Object.Instantiate(bulletPrefab, base.transform.position + base.transform.right, base.transform.rotation).GetComponent<Rigidbody>().AddForce(base.transform.right * bulletSpeed, ForceMode.VelocityChange);
+ }
+ }
+}