Skip to content

Commit 6787bba

Browse files
committed
redoing ship controls
1 parent 1770cef commit 6787bba

File tree

9 files changed

+78
-17
lines changed

9 files changed

+78
-17
lines changed

3d Space Shooter/Assets/_project/Scenes/Main.unity

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3398,6 +3398,7 @@ MonoBehaviour:
33983398
m_Script: {fileID: 11500000, guid: 2281f4c2a9f0b5bb5935e631bb17c0fa, type: 3}
33993399
m_Name:
34003400
m_EditorClassIdentifier:
3401+
_duration: 10
34013402
--- !u!54 &1143532946915120791
34023403
Rigidbody:
34033404
m_ObjectHideFlags: 0
@@ -17371,11 +17372,14 @@ MonoBehaviour:
1737117372
m_Script: {fileID: 11500000, guid: 89fbcd3b94efd41b3989038306f19c6a, type: 3}
1737217373
m_Name:
1737317374
m_EditorClassIdentifier:
17374-
_movementInput: {fileID: 1292328209331252848}
17375+
_inputControls: {fileID: 1292328209331252848}
1737517376
_thrustForce: 7500
1737617377
_pitchForce: 2399
1737717378
_yawForce: 2000
1737817379
_rollForce: 1000
17380+
_blasters:
17381+
- {fileID: 2421867205600743989}
17382+
- {fileID: 9071191015319997490}
1737917383
--- !u!1 &6907367073426837087
1738017384
GameObject:
1738117385
m_ObjectHideFlags: 0
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class SerialManager : MonoBehaviour
6+
{
7+
// Start is called before the first frame update
8+
void Start()
9+
{
10+
11+
}
12+
13+
// Update is called once per frame
14+
void Update()
15+
{
16+
17+
}
18+
}

3d Space Shooter/Assets/_project/scripts/Managers/SerialManager.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3d Space Shooter/Assets/_project/scripts/ShipControls/DesktopMovementControls.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ public class DesktopMovementControls : MovementControlsBase
1010
public override float YawAmount {
1111
get
1212
{
13-
if (Input.GetKey(KeyCode.A)) {
13+
if (Input.GetKey(KeyCode.D)) {
1414
return 1f;
1515
}
16-
return Input.GetKey(KeyCode.D) ? -1f : 0f;
16+
return Input.GetKey(KeyCode.A) ? -1f : 0f;
1717
}
1818
}
1919
public override float PitchAmount {
2020
get
2121
{
22-
if (Input.GetKey(KeyCode.W)) {
22+
if (Input.GetKey(KeyCode.S)) {
2323
return 1f;
2424
}
25-
return Input.GetKey(KeyCode.S) ? -1f : 0f;
25+
return Input.GetKey(KeyCode.W) ? -1f : 0f;
2626
}
2727
}
2828
public override float RollAmount {

3d Space Shooter/Assets/_project/scripts/ShipControls/ShipController.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,40 @@
66
public class ShipController : MonoBehaviour
77
{
88
[InlineEditor(InlineEditorObjectFieldModes.Boxed)]
9-
[SerializeField] [Required] ShipMovementInput _movementInput;
9+
[SerializeField] [Required] ShipInputControls _inputControls;
1010

1111
[BoxGroup("Ship Movement Values")][SerializeField] [Range(1000f, 10000f)]
1212
float _thrustForce = 7500f,
1313
_pitchForce = 6000f,
1414
_yawForce = 2000f,
1515
_rollForce = 1000f;
16+
17+
[BoxGroup("Ship Components")] [SerializeField]
18+
private List<Blaster> _blasters;
1619

1720
Rigidbody _rigidbody;
1821

1922
[ShowInInspector][Range(-1.0f,1.0f)]
2023
float _thrustAmount, _pitchAmount, _yawAmount, _rollAmount;
2124

22-
ImovementControls ControlInput => _movementInput.MovementControls;
25+
ImovementControls MovementInput => _inputControls.MovementControls;
26+
IWeaponControls WeaponInput => _inputControls.WeaponControls;
27+
28+
void Start() {
29+
foreach (Blaster blaster in _blasters) {
30+
blaster.Init(WeaponInput);
31+
}
32+
}
2333

2434
void Awake() {
2535
_rigidbody = GetComponent<Rigidbody>();
2636
}
2737

2838
void Update() {
29-
_thrustAmount = ControlInput.ThrustAmount;
30-
_pitchAmount = ControlInput.PitchAmount;
31-
_rollAmount = ControlInput.RollAmount;
32-
_yawAmount = ControlInput.YawAmount;
39+
_thrustAmount = MovementInput.ThrustAmount;
40+
_pitchAmount = MovementInput.PitchAmount;
41+
_rollAmount = MovementInput.RollAmount;
42+
_yawAmount = MovementInput.YawAmount;
3343
}
3444

3545
void FixedUpdate() {
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
31
using UnityEngine;
42

5-
public class ShipMovementInput : MonoBehaviour
3+
public class ShipInputControls : MonoBehaviour
64
{
75
[SerializeField] ShipInputManager.InputType _inputType = ShipInputManager.InputType.HumanDesktop;
86

97
public ImovementControls MovementControls {get; private set;}
8+
public IWeaponControls WeaponControls {get; private set;}
109

1110
// Start is called before the first frame update
1211
void Start()
1312
{
14-
MovementControls = ShipInputManager.GetInputControls(_inputType);
13+
MovementControls = ShipInputManager.GetMovementControls(_inputType);
14+
WeaponControls = ShipInputManager.GetWeaponControls(_inputType);
1515

1616
}
1717

1818
// Update is called once per frame
1919
void OnDestroy()
2020
{
2121
MovementControls = null;
22+
WeaponControls = null;
2223

2324
}
2425
}

3d Space Shooter/Assets/_project/scripts/ShipControls/ShipInputManager.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@ public enum InputType {
1212
Bot
1313
}
1414

15-
public static ImovementControls GetInputControls(InputType inputType) {
15+
public static ImovementControls GetMovementControls(InputType inputType) {
1616
return inputType switch {
1717
InputType.HumanDesktop => new DesktopMovementControls(),
1818
InputType.HumanMobile => null,
1919
InputType.Bot => null,
2020
_ => throw new ArgumentOutOfRangeException(nameof(inputType), inputType, null),
2121
};
2222

23+
}
24+
public static IWeaponControls GetWeaponControls(InputType inputType) {
25+
return inputType switch {
26+
InputType.HumanDesktop => new DesktopWeaponControls(),
27+
InputType.HumanMobile => null,
28+
InputType.Bot => null,
29+
_ => throw new ArgumentOutOfRangeException(nameof(inputType), inputType, null),
30+
};
31+
2332
}
2433

2534
}

3d Space Shooter/Assets/_project/scripts/weapons/Blaster.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections;
23
using System.Collections.Generic;
34
using Sirenix.OdinInspector;
@@ -8,6 +9,8 @@ public class Blaster : MonoBehaviour
89
[SerializeField] [Required] Projectile _projectilePrefab;
910
[SerializeField] Transform _muzzle;
1011
[SerializeField] [Range(0f, 5f)] float _coolDownTime = .25f;
12+
13+
private IWeaponControls _weaponInput;
1114

1215
bool CanFire {
1316
get {
@@ -30,7 +33,7 @@ void Update()
3033
if (_coolDown > 0 ) {
3134
_coolDown -= Time.deltaTime;
3235
}
33-
if (Input.GetMouseButton(0))
36+
if (_weaponInput != null && _weaponInput.PrimaryFired)
3437
{
3538
FireProjectile();
3639
}
@@ -45,4 +48,9 @@ public void FireProjectile()
4548
_coolDown = _coolDownTime;
4649
Instantiate(_projectilePrefab, _muzzle.position, transform.rotation);
4750
}
51+
52+
internal void Init(IWeaponControls weaponInput)
53+
{
54+
_weaponInput = weaponInput;
55+
}
4856
}

0 commit comments

Comments
 (0)