From 88496c99aeac52426aaed65762cfa190af0ffcc0 Mon Sep 17 00:00:00 2001 From: Saibotk Date: Mon, 23 Apr 2018 21:25:35 +0200 Subject: [PATCH] Fixes #30 --- Assets/Scenes/CodeDEV.unity | 6 +++++- Assets/Scripts/Bullet.cs | 18 +++++++++++------- Assets/Scripts/Entities/Attack/SingleShot.cs | 3 ++- Assets/Scripts/Entities/Player.cs | 3 +-- Assets/Scripts/GameController.cs | 2 +- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Assets/Scenes/CodeDEV.unity b/Assets/Scenes/CodeDEV.unity index efe074a..a0fed13 100644 --- a/Assets/Scenes/CodeDEV.unity +++ b/Assets/Scenes/CodeDEV.unity @@ -1153,7 +1153,7 @@ Prefab: - target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} propertyPath: m_AnchoredPosition.x - value: 66.396866 + value: 65.89836 objectReference: {fileID: 0} - target: {fileID: 224150154901314796, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} @@ -1185,6 +1185,10 @@ Prefab: propertyPath: m_SizeDelta.x value: 0 objectReference: {fileID: 0} + - target: {fileID: 1604998495297016, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 460d856ea4eb14cedb5fecde1fe6d743, type: 2} m_IsPrefabParent: 0 diff --git a/Assets/Scripts/Bullet.cs b/Assets/Scripts/Bullet.cs index faaf453..5527478 100644 --- a/Assets/Scripts/Bullet.cs +++ b/Assets/Scripts/Bullet.cs @@ -7,13 +7,17 @@ public class Bullet : MonoBehaviour { protected float speed = 1; [SerializeField] int damage = 0; - - GameObject owner; + [SerializeField] + bool start = false; + string ownertag; Rigidbody2D body; // Use this for initialization void Start () { body = GetComponent(); + } + public void StartBullet() { + start = true; } public void SetSpeed(float spd) { @@ -25,25 +29,25 @@ public class Bullet : MonoBehaviour { } public void SetOwner(GameObject ow) { - owner = ow; + ownertag = ow.tag; } private void FixedUpdate() { - if ( owner == null ) + if ( start == false ) return; body.MovePosition(transform.position + transform.localRotation * Vector3.up * speed * Time.fixedDeltaTime); } void OnTriggerEnter2D(Collider2D collider) { - if ( owner == null ) + if ( ownertag == null ) return; - if ( collider.gameObject.tag != owner.tag ) { + if ( collider.gameObject.tag != ownertag ) { Mob m = collider.gameObject.GetComponent(typeof(Mob)) as Mob; if (m != null) { m.InflictDamage(damage); } - Destroy(this.gameObject); + Destroy(gameObject); } } diff --git a/Assets/Scripts/Entities/Attack/SingleShot.cs b/Assets/Scripts/Entities/Attack/SingleShot.cs index e6b7b3b..8bef022 100644 --- a/Assets/Scripts/Entities/Attack/SingleShot.cs +++ b/Assets/Scripts/Entities/Attack/SingleShot.cs @@ -41,7 +41,8 @@ namespace Assets.Scripts.Entities.Attack { bu.SetDamage(damage); bu.SetSpeed(speed); bu.SetOwner(owner); - GameController.instance.GetAudioControl().SfxPlay(AudioControl.Sfx.shoot); + bu.StartBullet(); + GameController.instance.GetAudioControl().SfxPlay(AudioControl.Sfx.shoot); } public float GetCooldownTime() { diff --git a/Assets/Scripts/Entities/Player.cs b/Assets/Scripts/Entities/Player.cs index 084d93b..2f0fe01 100644 --- a/Assets/Scripts/Entities/Player.cs +++ b/Assets/Scripts/Entities/Player.cs @@ -45,9 +45,8 @@ public class Player : Mob { } if ( Time.timeSinceLevelLoad >= nextAttackTime && attack != null) { if ( Input.GetAxis("Fire") > 0 ) { - Debug.Log("Attack pressed!"); attack.Attack(); - nextAttackTime = Time.timeSinceLevelLoad + attack.GetCooldownTime(); + nextAttackTime = Time.timeSinceLevelLoad + attack.GetCooldownTime(); // Todo put in attack() } } // scale particle emissions by speed diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index c3e52ca..f8e37e3 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -333,7 +333,7 @@ public class GameController : MonoBehaviour { } public void EndGame(EndedCause cause) { - if (endCause != null && state == GameState.ENDED) + if (state == GameState.ENDED) return; // Already ended game endCause = cause; ChangeState(GameState.ENDED);