-
Notifications
You must be signed in to change notification settings - Fork 76
Version5 #34
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?
Version5 #34
Changes from all commits
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,36 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
| using System.Linq; | ||
|
|
||
| public class Player : MonoBehaviour | ||
| { | ||
| [SerializeField] private Transform _enemiesContainer; | ||
| [SerializeField] private Transform _finishPanel; | ||
|
|
||
| public int EnemiesOnLevel { get; private set; } | ||
|
|
||
| public int KilledEnemys { get; private set; } = 0; | ||
|
Comment on lines
+10
to
+12
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. Можно обойтись одним состоянием: оставшиеся на уровне |
||
|
|
||
| private void Start () | ||
| { | ||
| var enemies = _enemiesContainer.GetComponentsInChildren<Square>(); | ||
| EnemiesOnLevel = enemies.Count(); | ||
| } | ||
|
|
||
| private void OnTriggerEnter2D (Collider2D collision) | ||
| { | ||
| if (collision.GetComponent<Square>()) | ||
| { | ||
| EnemiesOnLevel--; | ||
|
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. Возможно это тоже не его ответственность |
||
|
|
||
| if (EnemiesOnLevel == 0) | ||
| OnLevelPassed(); | ||
|
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. Кинуть событие |
||
| } | ||
| } | ||
|
|
||
| private void OnLevelPassed () | ||
| { | ||
| Time.timeScale = 0; | ||
| _finishPanel.gameObject.SetActive(true); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| public class PlayerMover : MonoBehaviour | ||
| { | ||
| [SerializeField] private float _speed; | ||
|
|
||
| private float _boosterTime = 0; | ||
| private float _boosterForce = 0; | ||
| private float _defaultSpeed; | ||
|
|
||
| private void Start () | ||
| { | ||
| _defaultSpeed = _speed; | ||
| } | ||
|
|
||
| private void OnTriggerEnter2D (Collider2D collision) | ||
| { | ||
| if (collision.TryGetComponent(out SquareBooster squareBooster)) | ||
| { | ||
| _boosterForce = squareBooster.BoosterForce; | ||
| _boosterTime = squareBooster.BoosterTime; | ||
|
Comment on lines
+22
to
+23
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. В полях это хранить не надо, надо передать методу
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. Прочитай про чистые функции |
||
|
|
||
| StartCoroutine(Booster()); | ||
| } | ||
| } | ||
|
|
||
| private IEnumerator Booster () | ||
| { | ||
| var waitForSeconds = new WaitForSeconds(_boosterTime); | ||
| ChangeSpeed(_speed + _boosterForce); | ||
|
|
||
| for (int i = 0; i < 1; i++) | ||
| { | ||
| yield return waitForSeconds; | ||
| } | ||
|
|
||
| ChangeSpeed(_defaultSpeed); | ||
| StopCoroutine(Booster()); | ||
| } | ||
|
Comment on lines
+29
to
+41
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. переделать |
||
|
|
||
| private void ChangeSpeed (float speed) | ||
| { | ||
| _speed = speed; | ||
| } | ||
|
Comment on lines
+43
to
+46
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. Лишняя функция |
||
|
|
||
| private void Update () | ||
| { | ||
| Vector3 moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0); | ||
|
|
||
| transform.Translate(moveDirection * _speed * Time.deltaTime); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| public class Square : MonoBehaviour | ||
| { | ||
| [SerializeField] private float _speed = 2; | ||
| [SerializeField] private float _movementRadius = 4; | ||
|
|
||
| private Vector3 _target; | ||
|
|
||
| private void OnTriggerEnter2D (Collider2D collision) | ||
| { | ||
| if (collision.GetComponent<Player>()) | ||
| gameObject.SetActive(false); | ||
| } | ||
|
|
||
| private void Start () | ||
| { | ||
| CreateNewTarget(); | ||
| } | ||
|
|
||
| private void Update () | ||
| { | ||
| transform.position = Vector3.MoveTowards(transform.position, _target, _speed * Time.deltaTime); | ||
|
|
||
| if (transform.position == _target) | ||
| CreateNewTarget(); | ||
| } | ||
|
|
||
| protected void CreateNewTarget () | ||
| { | ||
| _target = Random.insideUnitCircle * _movementRadius; | ||
| } | ||
| } |
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,13 @@ | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| public class SquareBooster : Square | ||
| { | ||
| [SerializeField] private float _boosterForce; | ||
| [SerializeField] private float _boosterTime; | ||
|
|
||
| public float BoosterForce => _boosterForce; | ||
| public float BoosterTime => _boosterTime; | ||
|
|
||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Слишком много ответственностей