-
Notifications
You must be signed in to change notification settings - Fork 76
MyFirstRefactoring #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f96b3cf
dbf194d
afb418a
3c33d76
dedb07f
df54f55
7e85049
49bc8b7
d108533
6cfaa17
32971ed
bd1f052
8b68b3a
e6d1ae8
690b26d
4b84a5d
47127db
de52a33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using UnityEngine.Events; | ||
|
|
||
| [RequireComponent(typeof(EnemyMover))] | ||
| public class Enemy : MonoBehaviour | ||
| { | ||
| public event OnDied Died; | ||
|
|
||
| public delegate void OnDied(Enemy sender); | ||
|
|
||
| private void OnTriggerEnter2D(Collider2D collision) | ||
| { | ||
| if (collision.TryGetComponent<Player>(out Player player)) | ||
| { | ||
| Died?.Invoke(this); | ||
|
|
||
| Destroy(gameObject); | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| [RequireComponent(typeof(Rigidbody2D))] | ||
| [RequireComponent(typeof(CircleCollider2D))] | ||
| public class EnemyMover : MonoBehaviour | ||
| { | ||
| [SerializeField] private Rigidbody2D _rigidbody; | ||
| [SerializeField] private float _speed; | ||
| [SerializeField] private float _radius; | ||
|
|
||
| private Vector3 _target; | ||
|
|
||
| private void Start() | ||
| { | ||
| _target = GetTargetPosition(); | ||
| } | ||
|
|
||
| private void Update() | ||
| { | ||
| transform.position = Vector3.MoveTowards(transform.position, _target, _speed * Time.deltaTime); | ||
|
|
||
| if (transform.position == _target) | ||
| _target = GetTargetPosition(); | ||
| } | ||
|
|
||
| private Vector2 GetTargetPosition() | ||
| { | ||
| return Random.insideUnitCircle * _radius; | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using UnityEngine.UI; | ||
| using System.Linq; | ||
|
|
||
| public class LevelFinisher : MonoBehaviour | ||
| { | ||
| [SerializeField] private GameObject _menu; | ||
|
|
||
| private List<Enemy> _aliveEnemies; | ||
|
|
||
| private void Start() | ||
| { | ||
| _aliveEnemies = GetComponentsInChildren<Enemy>().ToList<Enemy>(); | ||
| } | ||
|
|
||
| private void OnEnable() | ||
| { | ||
| foreach (Enemy enemy in _aliveEnemies) | ||
| { | ||
| enemy.Died += AddKilledEnemy; | ||
| } | ||
| } | ||
|
|
||
| private void OnDisable() | ||
| { | ||
| foreach (Enemy enemy in _aliveEnemies) | ||
| { | ||
| enemy.Died -= AddKilledEnemy; | ||
| } | ||
| } | ||
|
|
||
| private void AddKilledEnemy(Enemy enemy) | ||
| { | ||
| _aliveEnemies.Remove(enemy); | ||
|
|
||
| if (_aliveEnemies.Count <= 0) | ||
| { | ||
| _menu.SetActive(true); | ||
| gameObject.SetActive(false); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
|
|
||
| [RequireComponent(typeof(Collider2D))] | ||
| [RequireComponent(typeof(Rigidbody2D))] | ||
| public class Player : MonoBehaviour | ||
| { | ||
| [SerializeField] private float _moveSpeed; | ||
| [SerializeField] private Rigidbody2D _rigidbody; | ||
|
|
||
| private void Update() | ||
| { | ||
| _rigidbody.velocity = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")) * _moveSpeed; | ||
| } | ||
|
|
||
| public IEnumerator BoostSpeed(float duration, float multiplier) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А вот это охуительно сделано. Молодец! |
||
| { | ||
| _moveSpeed *= multiplier; | ||
|
|
||
| yield return new WaitForSeconds(duration); | ||
|
|
||
| _moveSpeed /= multiplier; | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| [RequireComponent(typeof(Collider2D))] | ||
| public class SpeedBooster : MonoBehaviour | ||
| { | ||
| [SerializeField] private float _boostDuration; | ||
| [SerializeField] private float _boostSpeedMultiplier; | ||
|
|
||
| private void OnTriggerEnter2D(Collider2D collision) | ||
| { | ||
| if (collision.gameObject.TryGetComponent<Player>(out Player player)) | ||
| { | ||
| StartCoroutine(player.BoostSpeed(_boostDuration, _boostSpeedMultiplier)); | ||
|
|
||
| Destroy(gameObject); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
|
|
||
| === Thu Dec 24 16:16:09 2020 | ||
|
|
||
| Packages were changed. | ||
| Update Mode: updateDependencies | ||
|
|
||
| The following packages were added: | ||
| com.unity.2d.sprite@1.0.0 | ||
| com.unity.2d.tilemap@1.0.0 | ||
| com.unity.ide.rider@1.1.4 | ||
| com.unity.ide.vscode@1.2.3 | ||
| com.unity.modules.androidjni@1.0.0 | ||
| com.unity.multiplayer-hlapi@1.0.6 | ||
| com.unity.test-framework@1.1.19 | ||
| com.unity.timeline@1.2.6 | ||
| com.unity.ugui@1.0.0 | ||
| com.unity.xr.legacyinputhelpers@2.1.6 | ||
| The following packages were updated: | ||
| com.unity.ads from version 2.0.8 to 3.5.2 | ||
| com.unity.analytics from version 3.2.2 to 3.3.5 | ||
| com.unity.collab-proxy from version 1.2.15 to 1.2.16 | ||
| com.unity.purchasing from version 2.0.3 to 2.1.1 | ||
| com.unity.textmeshpro from version 1.3.0 to 2.0.1 | ||
| The following packages were removed: | ||
| com.unity.package-manager-ui@2.0.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Делегаты мы сами не определяем, а если бы и определяли то стиль там не такой. Воспользуйся стандартными Action