Some things
This commit is contained in:
parent
6ba30e430e
commit
e4cc23e7f0
119 changed files with 70085 additions and 682 deletions
58
Assets/Scripts/BalanceCanvas.cs
Normal file
58
Assets/Scripts/BalanceCanvas.cs
Normal file
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class BalanceCanvas : MonoBehaviour {
|
||||
|
||||
public static BalanceCanvas instance;
|
||||
|
||||
[SerializeField] Canvas canvas;
|
||||
PlayerInput _playerInput;
|
||||
|
||||
public Action sliderChangedCallback;
|
||||
|
||||
[Header("Sliders")]
|
||||
[SerializeField] Slider speedSlider;
|
||||
[SerializeField] Slider deathForceSlider;
|
||||
[SerializeField] Slider jumpSlider;
|
||||
[SerializeField] Slider accelerationSlider;
|
||||
[SerializeField] Slider jumpCancelSlider;
|
||||
[SerializeField] Slider gravitySlider;
|
||||
[SerializeField] Slider coyoteTime;
|
||||
[SerializeField] Slider bufferTime;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake() {
|
||||
instance = this;
|
||||
|
||||
_playerInput = new PlayerInput();
|
||||
_playerInput.Gameplay.Cancel.started += CanvasStateSwitch;
|
||||
|
||||
SetupSlider(speedSlider, nameof(PlayerStats.speed));
|
||||
SetupSlider(deathForceSlider, nameof(PlayerStats.deathForce));
|
||||
SetupSlider(accelerationSlider, nameof(PlayerStats.acceleration));
|
||||
SetupSlider(jumpSlider, nameof(PlayerStats.jumpForce));
|
||||
SetupSlider(jumpCancelSlider, nameof(PlayerStats.jumpCancellationMultiplier));
|
||||
SetupSlider(gravitySlider, nameof(PlayerStats.Rb.gravityScale));
|
||||
SetupSlider(coyoteTime, nameof(PlayerStats.coyoteTime));
|
||||
SetupSlider(bufferTime, nameof(PlayerStats.bufferTime));
|
||||
}
|
||||
|
||||
void SliderChangedCallback(float arg0) => sliderChangedCallback?.Invoke();
|
||||
|
||||
void SetupSlider(Slider slider, string valueName) {
|
||||
slider.onValueChanged.AddListener(value => {
|
||||
PlayerPrefs.SetFloat(valueName, value);
|
||||
});
|
||||
slider.onValueChanged.AddListener(SliderChangedCallback);
|
||||
slider.SetValueWithoutNotify(PlayerPrefs.GetFloat(valueName, slider.value));
|
||||
}
|
||||
|
||||
void CanvasStateSwitch(InputAction.CallbackContext obj) {
|
||||
canvas.enabled ^= true;
|
||||
}
|
||||
|
||||
void OnEnable() => _playerInput.Enable();
|
||||
void OnDisable() => _playerInput.Disable();
|
||||
}
|
11
Assets/Scripts/BalanceCanvas.cs.meta
Normal file
11
Assets/Scripts/BalanceCanvas.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3df8b3cc67547654d91e2d84b71c02e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,17 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Bullet1 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
public void AddForce(int direction) {
|
||||
Rigidbody2D rb = GetComponent<Rigidbody2D>();
|
||||
rb.velocity = Vector2.right * direction * speed;
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D other) {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Enemy1 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
[SerializeField] LayerMask groundLayer;
|
||||
|
||||
[Header("Flipping Pivots")]
|
||||
[SerializeField] Transform flippingPivotLeft;
|
||||
[SerializeField] Transform flippingPivotRight;
|
||||
|
||||
int _facingDirection = 1;
|
||||
Rigidbody2D _rb;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake() {
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate() {
|
||||
if (_facingDirection > 0) {
|
||||
if (Physics2D.OverlapBox(flippingPivotRight.position, flippingPivotRight.localScale, 0, groundLayer)) {
|
||||
_facingDirection = -1;
|
||||
transform.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
}else {
|
||||
if (Physics2D.OverlapBox(flippingPivotLeft.position, flippingPivotLeft.localScale, 0, groundLayer)) {
|
||||
_facingDirection = 1;
|
||||
transform.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
_rb.velocity = new Vector2(speed * _facingDirection, _rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
if(!flippingPivotLeft || !flippingPivotRight) return;
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
|
||||
Gizmos.DrawWireCube(flippingPivotLeft.position, flippingPivotLeft.localScale);
|
||||
Gizmos.DrawWireCube(flippingPivotRight.position, flippingPivotRight.localScale);
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyWeakPoint1 : MonoBehaviour {
|
||||
|
||||
Enemy1 _enemy;
|
||||
|
||||
void Awake() {
|
||||
_enemy = GetComponentInParent<Enemy1>();
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other) {
|
||||
if (!other.CompareTag("Player")) return;
|
||||
PlayerMovement1 player = other.GetComponent<PlayerMovement1>();
|
||||
|
||||
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
|
||||
player.Animator.SetTrigger(PlayerMovement1.Jump1);
|
||||
Destroy(_enemy.gameObject);
|
||||
}
|
||||
}
|
8
Assets/Scripts/Level 1.meta
Normal file
8
Assets/Scripts/Level 1.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8cc854c8265c0ce41a4fa4fc46717bf3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
16
Assets/Scripts/Level 1/Bullet1.cs
Normal file
16
Assets/Scripts/Level 1/Bullet1.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level1 {
|
||||
public class Bullet1 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
public void AddForce(int direction) {
|
||||
Rigidbody2D rb = GetComponent<Rigidbody2D>();
|
||||
rb.velocity = Vector2.right * direction * speed;
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D other) {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
48
Assets/Scripts/Level 1/Enemy1.cs
Normal file
48
Assets/Scripts/Level 1/Enemy1.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level1 {
|
||||
public class Enemy1 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
[SerializeField] LayerMask groundLayer;
|
||||
|
||||
[SerializeField] Transform sprite;
|
||||
|
||||
[Header("Flipping Pivots")]
|
||||
[SerializeField] Transform flippingPivotLeft;
|
||||
[SerializeField] Transform flippingPivotRight;
|
||||
|
||||
int _facingDirection = 1;
|
||||
Rigidbody2D _rb;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake() {
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate() {
|
||||
if (_facingDirection > 0) {
|
||||
if (Physics2D.OverlapBox(flippingPivotRight.position, flippingPivotRight.localScale, 0, groundLayer)) {
|
||||
_facingDirection = -1;
|
||||
sprite.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
}else {
|
||||
if (Physics2D.OverlapBox(flippingPivotLeft.position, flippingPivotLeft.localScale, 0, groundLayer)) {
|
||||
_facingDirection = 1;
|
||||
sprite.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
_rb.velocity = new Vector2(speed * _facingDirection, _rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
if(!flippingPivotLeft || !flippingPivotRight) return;
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
|
||||
Gizmos.DrawWireCube(flippingPivotLeft.position, flippingPivotLeft.localScale);
|
||||
Gizmos.DrawWireCube(flippingPivotRight.position, flippingPivotRight.localScale);
|
||||
}
|
||||
}
|
||||
}
|
21
Assets/Scripts/Level 1/EnemyWeakPoint1.cs
Normal file
21
Assets/Scripts/Level 1/EnemyWeakPoint1.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level1 {
|
||||
public class EnemyWeakPoint1 : MonoBehaviour {
|
||||
|
||||
Enemy1 _enemy;
|
||||
|
||||
void Awake() {
|
||||
_enemy = GetComponentInParent<Enemy1>();
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other) {
|
||||
if (!other.CompareTag("Player")) return;
|
||||
PlayerMovement1 player = other.GetComponent<PlayerMovement1>();
|
||||
|
||||
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
|
||||
player.Animator.SetTrigger(PlayerMovement1.Jump1);
|
||||
Destroy(_enemy.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
84
Assets/Scripts/Level 1/PlayerMovement1.cs
Normal file
84
Assets/Scripts/Level 1/PlayerMovement1.cs
Normal file
|
@ -0,0 +1,84 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Level1 {
|
||||
public class PlayerMovement1 : PlayerStats {
|
||||
[Header("Shooting")]
|
||||
[SerializeField] Bullet1 bullet;
|
||||
[SerializeField] Transform shootingPos;
|
||||
|
||||
[Header("Physics")]
|
||||
[SerializeField] LayerMask groundMask;
|
||||
[SerializeField] Vector2 feetSize;
|
||||
|
||||
float _horizontalInput;
|
||||
bool _grounded;
|
||||
|
||||
int _facingDirection = 1;
|
||||
|
||||
PlayerInput _playerInput;
|
||||
|
||||
[Header("Animations")]
|
||||
[SerializeField] Animator animator;
|
||||
public Animator Animator => animator;
|
||||
|
||||
public static readonly int Jump1 = Animator.StringToHash("Jump");
|
||||
static readonly int XVelocity = Animator.StringToHash("xVelocity");
|
||||
static readonly int YVelocity = Animator.StringToHash("yVelocity");
|
||||
static readonly int Grounded = Animator.StringToHash("Grounded");
|
||||
|
||||
void Awake() {
|
||||
_playerInput = new PlayerInput();
|
||||
|
||||
_playerInput.Gameplay.Horizontal.started += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.performed += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.canceled += HorizontalHandler;
|
||||
|
||||
_playerInput.Gameplay.Jump.performed += Jump;
|
||||
|
||||
_playerInput.Gameplay.Fire.performed += Fire;
|
||||
}
|
||||
|
||||
void Jump(InputAction.CallbackContext obj) {
|
||||
if (!_grounded) return;
|
||||
Rb.velocity = new Vector2(Rb.velocity.x, jumpForce);
|
||||
animator.SetTrigger(Jump1);
|
||||
}
|
||||
|
||||
void Fire(InputAction.CallbackContext obj) {
|
||||
Bullet1 bullet1 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
|
||||
bullet1.AddForce(_facingDirection);
|
||||
}
|
||||
|
||||
void HorizontalHandler(InputAction.CallbackContext obj) {
|
||||
_horizontalInput = obj.ReadValue<float>();
|
||||
_facingDirection = _horizontalInput > 0 ? 1 : _horizontalInput < 0 ? -1 : _facingDirection;
|
||||
transform.localScale = new Vector3(_facingDirection, 1, 1);
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
_playerInput.Enable();
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
_playerInput.Disable();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
animator.SetFloat(XVelocity, Mathf.Abs(_horizontalInput * speed));
|
||||
animator.SetFloat(YVelocity, Rb.velocity.y);
|
||||
animator.SetBool(Grounded, _grounded);
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
_grounded = Physics2D.OverlapBox(transform.position, feetSize, 0, groundMask);
|
||||
Rb.velocity = new Vector2(_horizontalInput * speed, Rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, feetSize);
|
||||
}
|
||||
}
|
||||
}
|
8
Assets/Scripts/Level 2.meta
Normal file
8
Assets/Scripts/Level 2.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6e2ca47064ba93f4a8de0e358b3e52bd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
16
Assets/Scripts/Level 2/Bullet2.cs
Normal file
16
Assets/Scripts/Level 2/Bullet2.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level2 {
|
||||
public class Bullet2 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
public void AddForce(int direction) {
|
||||
Rigidbody2D rb = GetComponent<Rigidbody2D>();
|
||||
rb.velocity = Vector2.right * direction * speed;
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D other) {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 2/Bullet2.cs.meta
Normal file
11
Assets/Scripts/Level 2/Bullet2.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 04770de73ff9b8341ba79de1bc002363
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
48
Assets/Scripts/Level 2/Enemy2.cs
Normal file
48
Assets/Scripts/Level 2/Enemy2.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level2 {
|
||||
public class Enemy2 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
[SerializeField] LayerMask groundLayer;
|
||||
|
||||
[SerializeField] Transform sprite;
|
||||
|
||||
[Header("Flipping Pivots")]
|
||||
[SerializeField] Transform flippingPivotLeft;
|
||||
[SerializeField] Transform flippingPivotRight;
|
||||
|
||||
int _facingDirection = 1;
|
||||
Rigidbody2D _rb;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake() {
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate() {
|
||||
if (_facingDirection > 0) {
|
||||
if (Physics2D.OverlapBox(flippingPivotRight.position, flippingPivotRight.localScale, 0, groundLayer)) {
|
||||
_facingDirection = -1;
|
||||
sprite.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
}else {
|
||||
if (Physics2D.OverlapBox(flippingPivotLeft.position, flippingPivotLeft.localScale, 0, groundLayer)) {
|
||||
_facingDirection = 1;
|
||||
sprite.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
_rb.velocity = new Vector2(speed * _facingDirection, _rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
if(!flippingPivotLeft || !flippingPivotRight) return;
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
|
||||
Gizmos.DrawWireCube(flippingPivotLeft.position, flippingPivotLeft.localScale);
|
||||
Gizmos.DrawWireCube(flippingPivotRight.position, flippingPivotRight.localScale);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 2/Enemy2.cs.meta
Normal file
11
Assets/Scripts/Level 2/Enemy2.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2da43d11698bc524ba6cfd8084a24c8c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
22
Assets/Scripts/Level 2/EnemyWeakPoint2.cs
Normal file
22
Assets/Scripts/Level 2/EnemyWeakPoint2.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using Level1;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level2 {
|
||||
public class EnemyWeakPoint2 : MonoBehaviour {
|
||||
|
||||
Enemy2 _enemy;
|
||||
|
||||
void Awake() {
|
||||
_enemy = GetComponentInParent<Enemy2>();
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other) {
|
||||
if (!other.CompareTag("Player")) return;
|
||||
PlayerMovement2 player = other.GetComponent<PlayerMovement2>();
|
||||
|
||||
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
|
||||
player.Animator.SetTrigger(PlayerMovement2.Jump1);
|
||||
Destroy(_enemy.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Level 2/EnemyWeakPoint2.cs.meta
Normal file
3
Assets/Scripts/Level 2/EnemyWeakPoint2.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fa654fa0bf77d95459b9fa7b1058f043
|
||||
timeCreated: 1691603524
|
90
Assets/Scripts/Level 2/PlayerMovement2.cs
Normal file
90
Assets/Scripts/Level 2/PlayerMovement2.cs
Normal file
|
@ -0,0 +1,90 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Level2 {
|
||||
public class PlayerMovement2 : PlayerStats {
|
||||
[Header("Shooting")]
|
||||
[SerializeField] Bullet2 bullet;
|
||||
[SerializeField] Transform shootingPos;
|
||||
|
||||
[Header("Physics")]
|
||||
[SerializeField] LayerMask groundMask;
|
||||
[SerializeField] Vector2 feetSize;
|
||||
|
||||
float _horizontalInput;
|
||||
float _xVelocity;
|
||||
float _accelerationVelocity;
|
||||
bool _grounded;
|
||||
|
||||
int _facingDirection = 1;
|
||||
|
||||
PlayerInput _playerInput;
|
||||
|
||||
[Header("Animations")]
|
||||
[SerializeField] Animator animator;
|
||||
public Animator Animator => animator;
|
||||
|
||||
public static readonly int Jump1 = Animator.StringToHash("Jump");
|
||||
static readonly int XVelocity = Animator.StringToHash("xVelocity");
|
||||
static readonly int YVelocity = Animator.StringToHash("yVelocity");
|
||||
static readonly int Grounded = Animator.StringToHash("Grounded");
|
||||
|
||||
void Awake() {
|
||||
_playerInput = new PlayerInput();
|
||||
|
||||
_playerInput.Gameplay.Horizontal.started += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.performed += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.canceled += HorizontalHandler;
|
||||
|
||||
_playerInput.Gameplay.Jump.performed += Jump;
|
||||
|
||||
_playerInput.Gameplay.Fire.performed += Fire;
|
||||
}
|
||||
|
||||
void Jump(InputAction.CallbackContext obj) {
|
||||
if (!_grounded) return;
|
||||
Rb.velocity = new Vector2(Rb.velocity.x, jumpForce);
|
||||
animator.SetTrigger(Jump1);
|
||||
}
|
||||
|
||||
void Fire(InputAction.CallbackContext obj) {
|
||||
Bullet2 bullet2 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
|
||||
bullet2.AddForce(_facingDirection);
|
||||
}
|
||||
|
||||
void HorizontalHandler(InputAction.CallbackContext obj) {
|
||||
_horizontalInput = obj.ReadValue<float>();
|
||||
_facingDirection = _horizontalInput > 0 ? 1 : _horizontalInput < 0 ? -1 : _facingDirection;
|
||||
transform.localScale = new Vector3(_facingDirection, 1, 1);
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
_playerInput.Enable();
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
_playerInput.Disable();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
animator.SetFloat(XVelocity, Mathf.Abs(_horizontalInput * speed));
|
||||
animator.SetFloat(YVelocity, Rb.velocity.y);
|
||||
animator.SetBool(Grounded, _grounded);
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
_grounded = Physics2D.OverlapBox(transform.position, feetSize, 0, groundMask);
|
||||
|
||||
_xVelocity = Rb.velocity.x;
|
||||
_xVelocity = Mathf.SmoothDamp(_xVelocity, _horizontalInput * speed, ref _accelerationVelocity,
|
||||
acceleration);;
|
||||
Rb.velocity = new Vector2(_xVelocity, Rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, feetSize);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 2/PlayerMovement2.cs.meta
Normal file
11
Assets/Scripts/Level 2/PlayerMovement2.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4b0574dd714a6f04598d2c12813ce5fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Level 3.meta
Normal file
8
Assets/Scripts/Level 3.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 08aade864f60ad14284517c85ce4ccf4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
16
Assets/Scripts/Level 3/Bullet3.cs
Normal file
16
Assets/Scripts/Level 3/Bullet3.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level3 {
|
||||
public class Bullet3 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
public void AddForce(int direction) {
|
||||
Rigidbody2D rb = GetComponent<Rigidbody2D>();
|
||||
rb.velocity = Vector2.right * direction * speed;
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D other) {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 3/Bullet3.cs.meta
Normal file
11
Assets/Scripts/Level 3/Bullet3.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 28a57b11603a86a4fbd75781d0cf7362
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
48
Assets/Scripts/Level 3/Enemy3.cs
Normal file
48
Assets/Scripts/Level 3/Enemy3.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level3 {
|
||||
public class Enemy3 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
[SerializeField] LayerMask groundLayer;
|
||||
|
||||
[SerializeField] Transform sprite;
|
||||
|
||||
[Header("Flipping Pivots")]
|
||||
[SerializeField] Transform flippingPivotLeft;
|
||||
[SerializeField] Transform flippingPivotRight;
|
||||
|
||||
int _facingDirection = 1;
|
||||
Rigidbody2D _rb;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake() {
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate() {
|
||||
if (_facingDirection > 0) {
|
||||
if (Physics2D.OverlapBox(flippingPivotRight.position, flippingPivotRight.localScale, 0, groundLayer)) {
|
||||
_facingDirection = -1;
|
||||
sprite.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
}else {
|
||||
if (Physics2D.OverlapBox(flippingPivotLeft.position, flippingPivotLeft.localScale, 0, groundLayer)) {
|
||||
_facingDirection = 1;
|
||||
sprite.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
_rb.velocity = new Vector2(speed * _facingDirection, _rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
if(!flippingPivotLeft || !flippingPivotRight) return;
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
|
||||
Gizmos.DrawWireCube(flippingPivotLeft.position, flippingPivotLeft.localScale);
|
||||
Gizmos.DrawWireCube(flippingPivotRight.position, flippingPivotRight.localScale);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 3/Enemy3.cs.meta
Normal file
11
Assets/Scripts/Level 3/Enemy3.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a702156cc07b52a40a370906dbc0d0f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
21
Assets/Scripts/Level 3/EnemyWeakPoint3.cs
Normal file
21
Assets/Scripts/Level 3/EnemyWeakPoint3.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level3 {
|
||||
public class EnemyWeakPoint3 : MonoBehaviour {
|
||||
|
||||
Enemy3 _enemy;
|
||||
|
||||
void Awake() {
|
||||
_enemy = GetComponentInParent<Enemy3>();
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other) {
|
||||
if (!other.CompareTag("Player")) return;
|
||||
PlayerMovement3 player = other.GetComponent<PlayerMovement3>();
|
||||
|
||||
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
|
||||
player.Animator.SetTrigger(PlayerMovement3.Jump1);
|
||||
Destroy(_enemy.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Level 3/EnemyWeakPoint3.cs.meta
Normal file
3
Assets/Scripts/Level 3/EnemyWeakPoint3.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d5f722c64c0b3f64db13d1756d378105
|
||||
timeCreated: 1691603524
|
97
Assets/Scripts/Level 3/PlayerMovement3.cs
Normal file
97
Assets/Scripts/Level 3/PlayerMovement3.cs
Normal file
|
@ -0,0 +1,97 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Level3 {
|
||||
public class PlayerMovement3 : PlayerStats {
|
||||
|
||||
[Header("Shooting")]
|
||||
[SerializeField] Bullet3 bullet;
|
||||
[SerializeField] Transform shootingPos;
|
||||
|
||||
[Header("Physics")]
|
||||
[SerializeField] LayerMask groundMask;
|
||||
[SerializeField] Vector2 feetSize;
|
||||
|
||||
float _horizontalInput;
|
||||
float _xVelocity;
|
||||
float _accelerationVelocity;
|
||||
bool _grounded;
|
||||
|
||||
int _facingDirection = 1;
|
||||
|
||||
PlayerInput _playerInput;
|
||||
|
||||
[Header("Animations")]
|
||||
[SerializeField] Animator animator;
|
||||
public Animator Animator => animator;
|
||||
|
||||
public static readonly int Jump1 = Animator.StringToHash("Jump");
|
||||
static readonly int XVelocity = Animator.StringToHash("xVelocity");
|
||||
static readonly int YVelocity = Animator.StringToHash("yVelocity");
|
||||
static readonly int Grounded = Animator.StringToHash("Grounded");
|
||||
|
||||
void Awake() {
|
||||
_playerInput = new PlayerInput();
|
||||
|
||||
_playerInput.Gameplay.Horizontal.started += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.performed += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.canceled += HorizontalHandler;
|
||||
|
||||
_playerInput.Gameplay.Jump.started += Jump;
|
||||
_playerInput.Gameplay.Jump.canceled += Jump;
|
||||
|
||||
_playerInput.Gameplay.Fire.performed += Fire;
|
||||
}
|
||||
|
||||
void Jump(InputAction.CallbackContext obj) {
|
||||
if (_grounded) {
|
||||
if(!obj.started) return;
|
||||
Rb.velocity = new Vector2(Rb.velocity.x, jumpForce);
|
||||
animator.SetTrigger(Jump1);
|
||||
}else if (Rb.velocity.y > 0f) {
|
||||
if(!obj.canceled) return;
|
||||
Rb.velocity = new Vector2(Rb.velocity.x, Rb.velocity.y * jumpCancellationMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
void Fire(InputAction.CallbackContext obj) {
|
||||
Bullet3 bullet3 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
|
||||
bullet3.AddForce(_facingDirection);
|
||||
}
|
||||
|
||||
void HorizontalHandler(InputAction.CallbackContext obj) {
|
||||
_horizontalInput = obj.ReadValue<float>();
|
||||
_facingDirection = _horizontalInput > 0 ? 1 : _horizontalInput < 0 ? -1 : _facingDirection;
|
||||
transform.localScale = new Vector3(_facingDirection, 1, 1);
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
_playerInput.Enable();
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
_playerInput.Disable();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
animator.SetFloat(XVelocity, Mathf.Abs(_horizontalInput * speed));
|
||||
animator.SetFloat(YVelocity, Rb.velocity.y);
|
||||
animator.SetBool(Grounded, _grounded);
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
_grounded = Physics2D.OverlapBox(transform.position, feetSize, 0, groundMask);
|
||||
|
||||
_xVelocity = Rb.velocity.x;
|
||||
_xVelocity = Mathf.SmoothDamp(_xVelocity, _horizontalInput * speed, ref _accelerationVelocity,
|
||||
acceleration);;
|
||||
Rb.velocity = new Vector2(_xVelocity, Rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, feetSize);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 3/PlayerMovement3.cs.meta
Normal file
11
Assets/Scripts/Level 3/PlayerMovement3.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 79d5d988892965c498665dc1d77a8963
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Level 4.meta
Normal file
8
Assets/Scripts/Level 4.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a42c5593f366e8844b063a1e26ec122a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
16
Assets/Scripts/Level 4/Bullet4.cs
Normal file
16
Assets/Scripts/Level 4/Bullet4.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level4 {
|
||||
public class Bullet4 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
public void AddForce(int direction) {
|
||||
Rigidbody2D rb = GetComponent<Rigidbody2D>();
|
||||
rb.velocity = Vector2.right * direction * speed;
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D other) {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 4/Bullet4.cs.meta
Normal file
11
Assets/Scripts/Level 4/Bullet4.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8b14205774bec874485d67e1b23f2ef1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
48
Assets/Scripts/Level 4/Enemy4.cs
Normal file
48
Assets/Scripts/Level 4/Enemy4.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level4 {
|
||||
public class Enemy4 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
[SerializeField] LayerMask groundLayer;
|
||||
|
||||
[SerializeField] Transform sprite;
|
||||
|
||||
[Header("Flipping Pivots")]
|
||||
[SerializeField] Transform flippingPivotLeft;
|
||||
[SerializeField] Transform flippingPivotRight;
|
||||
|
||||
int _facingDirection = 1;
|
||||
Rigidbody2D _rb;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake() {
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate() {
|
||||
if (_facingDirection > 0) {
|
||||
if (Physics2D.OverlapBox(flippingPivotRight.position, flippingPivotRight.localScale, 0, groundLayer)) {
|
||||
_facingDirection = -1;
|
||||
sprite.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
}else {
|
||||
if (Physics2D.OverlapBox(flippingPivotLeft.position, flippingPivotLeft.localScale, 0, groundLayer)) {
|
||||
_facingDirection = 1;
|
||||
sprite.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
_rb.velocity = new Vector2(speed * _facingDirection, _rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
if(!flippingPivotLeft || !flippingPivotRight) return;
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
|
||||
Gizmos.DrawWireCube(flippingPivotLeft.position, flippingPivotLeft.localScale);
|
||||
Gizmos.DrawWireCube(flippingPivotRight.position, flippingPivotRight.localScale);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 4/Enemy4.cs.meta
Normal file
11
Assets/Scripts/Level 4/Enemy4.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b6d5d51871e194b468f567c5bcd8fcd0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
21
Assets/Scripts/Level 4/EnemyWeakPoint4.cs
Normal file
21
Assets/Scripts/Level 4/EnemyWeakPoint4.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level4 {
|
||||
public class EnemyWeakPoint4 : MonoBehaviour {
|
||||
|
||||
Enemy4 _enemy;
|
||||
|
||||
void Awake() {
|
||||
_enemy = GetComponentInParent<Enemy4>();
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other) {
|
||||
if (!other.CompareTag("Player")) return;
|
||||
PlayerMovement4 player = other.GetComponent<PlayerMovement4>();
|
||||
|
||||
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
|
||||
player.Animator.SetTrigger(PlayerMovement4.Jump1);
|
||||
Destroy(_enemy.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Level 4/EnemyWeakPoint4.cs.meta
Normal file
3
Assets/Scripts/Level 4/EnemyWeakPoint4.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b3836e6e5a2237b4585191bfea204e73
|
||||
timeCreated: 1691603524
|
104
Assets/Scripts/Level 4/PlayerMovement4.cs
Normal file
104
Assets/Scripts/Level 4/PlayerMovement4.cs
Normal file
|
@ -0,0 +1,104 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Level4 {
|
||||
public class PlayerMovement4 : PlayerStats {
|
||||
|
||||
[Header("Shooting")]
|
||||
[SerializeField] Bullet4 bullet;
|
||||
[SerializeField] Transform shootingPos;
|
||||
|
||||
[Header("Physics")]
|
||||
[SerializeField] LayerMask groundMask;
|
||||
[SerializeField] Vector2 feetSize;
|
||||
|
||||
float _horizontalInput;
|
||||
float _xVelocity;
|
||||
float _accelerationVelocity;
|
||||
float _currentCoyoteTime;
|
||||
bool _grounded;
|
||||
|
||||
int _facingDirection = 1;
|
||||
|
||||
PlayerInput _playerInput;
|
||||
|
||||
[Header("Animations")]
|
||||
[SerializeField] Animator animator;
|
||||
public Animator Animator => animator;
|
||||
|
||||
public static readonly int Jump1 = Animator.StringToHash("Jump");
|
||||
static readonly int XVelocity = Animator.StringToHash("xVelocity");
|
||||
static readonly int YVelocity = Animator.StringToHash("yVelocity");
|
||||
static readonly int Grounded = Animator.StringToHash("Grounded");
|
||||
|
||||
void Awake() {
|
||||
_playerInput = new PlayerInput();
|
||||
|
||||
_playerInput.Gameplay.Horizontal.started += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.performed += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.canceled += HorizontalHandler;
|
||||
|
||||
_playerInput.Gameplay.Jump.started += Jump;
|
||||
_playerInput.Gameplay.Jump.canceled += Jump;
|
||||
|
||||
_playerInput.Gameplay.Fire.performed += Fire;
|
||||
}
|
||||
|
||||
void Jump(InputAction.CallbackContext obj) {
|
||||
Debug.Log(_currentCoyoteTime);
|
||||
if (_currentCoyoteTime > 0f) {
|
||||
if(!obj.started) return;
|
||||
_currentCoyoteTime = 0f;
|
||||
Rb.velocity = new Vector2(Rb.velocity.x, jumpForce);
|
||||
animator.SetTrigger(Jump1);
|
||||
}else if (Rb.velocity.y > 0f) {
|
||||
if(!obj.canceled) return;
|
||||
Rb.velocity = new Vector2(Rb.velocity.x, Rb.velocity.y * jumpCancellationMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
void Fire(InputAction.CallbackContext obj) {
|
||||
Bullet4 bullet4 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
|
||||
bullet4.AddForce(_facingDirection);
|
||||
}
|
||||
|
||||
void HorizontalHandler(InputAction.CallbackContext obj) {
|
||||
_horizontalInput = obj.ReadValue<float>();
|
||||
_facingDirection = _horizontalInput > 0 ? 1 : _horizontalInput < 0 ? -1 : _facingDirection;
|
||||
transform.localScale = new Vector3(_facingDirection, 1, 1);
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
_playerInput.Enable();
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
_playerInput.Disable();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
animator.SetFloat(XVelocity, Mathf.Abs(_xVelocity));
|
||||
animator.SetFloat(YVelocity, Rb.velocity.y);
|
||||
animator.SetBool(Grounded, _grounded);
|
||||
|
||||
_currentCoyoteTime -= Time.deltaTime;
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
_grounded = Physics2D.OverlapBox(transform.position, feetSize, 0, groundMask);
|
||||
if (_grounded && Rb.velocity.y < .1f)
|
||||
_currentCoyoteTime = coyoteTime;
|
||||
|
||||
_xVelocity = Rb.velocity.x;
|
||||
_xVelocity = Mathf.SmoothDamp(_xVelocity, _horizontalInput * speed, ref _accelerationVelocity,
|
||||
acceleration);;
|
||||
Rb.velocity = new Vector2(_xVelocity, Rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, feetSize);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 4/PlayerMovement4.cs.meta
Normal file
11
Assets/Scripts/Level 4/PlayerMovement4.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5c23b96fd8abc2348bf90561b68b6d5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Level 5.meta
Normal file
8
Assets/Scripts/Level 5.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 20bfe985cfe41574eaaf365818a78141
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
16
Assets/Scripts/Level 5/Bullet5.cs
Normal file
16
Assets/Scripts/Level 5/Bullet5.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level5 {
|
||||
public class Bullet5 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
public void AddForce(int direction) {
|
||||
Rigidbody2D rb = GetComponent<Rigidbody2D>();
|
||||
rb.velocity = Vector2.right * direction * speed;
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D other) {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 5/Bullet5.cs.meta
Normal file
11
Assets/Scripts/Level 5/Bullet5.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 28dea3103ee8f394baae8557190249d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
48
Assets/Scripts/Level 5/Enemy5.cs
Normal file
48
Assets/Scripts/Level 5/Enemy5.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level5 {
|
||||
public class Enemy5 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
[SerializeField] LayerMask groundLayer;
|
||||
|
||||
[SerializeField] Transform sprite;
|
||||
|
||||
[Header("Flipping Pivots")]
|
||||
[SerializeField] Transform flippingPivotLeft;
|
||||
[SerializeField] Transform flippingPivotRight;
|
||||
|
||||
int _facingDirection = 1;
|
||||
Rigidbody2D _rb;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake() {
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate() {
|
||||
if (_facingDirection > 0) {
|
||||
if (Physics2D.OverlapBox(flippingPivotRight.position, flippingPivotRight.localScale, 0, groundLayer)) {
|
||||
_facingDirection = -1;
|
||||
sprite.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
}else {
|
||||
if (Physics2D.OverlapBox(flippingPivotLeft.position, flippingPivotLeft.localScale, 0, groundLayer)) {
|
||||
_facingDirection = 1;
|
||||
sprite.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
_rb.velocity = new Vector2(speed * _facingDirection, _rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
if(!flippingPivotLeft || !flippingPivotRight) return;
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
|
||||
Gizmos.DrawWireCube(flippingPivotLeft.position, flippingPivotLeft.localScale);
|
||||
Gizmos.DrawWireCube(flippingPivotRight.position, flippingPivotRight.localScale);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 5/Enemy5.cs.meta
Normal file
11
Assets/Scripts/Level 5/Enemy5.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4bde3b56be48bd647b7d5019c615889e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
21
Assets/Scripts/Level 5/EnemyWeakPoint5.cs
Normal file
21
Assets/Scripts/Level 5/EnemyWeakPoint5.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level5 {
|
||||
public class EnemyWeakPoint5 : MonoBehaviour {
|
||||
|
||||
Enemy5 _enemy;
|
||||
|
||||
void Awake() {
|
||||
_enemy = GetComponentInParent<Enemy5>();
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other) {
|
||||
if (!other.CompareTag("Player")) return;
|
||||
PlayerMovement5 player = other.GetComponent<PlayerMovement5>();
|
||||
|
||||
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
|
||||
player.Animator.SetTrigger(PlayerMovement5.Jump1);
|
||||
Destroy(_enemy.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Level 5/EnemyWeakPoint5.cs.meta
Normal file
3
Assets/Scripts/Level 5/EnemyWeakPoint5.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c1c8859dd6272f14d9347269bd6f8214
|
||||
timeCreated: 1691603524
|
107
Assets/Scripts/Level 5/PlayerMovement5.cs
Normal file
107
Assets/Scripts/Level 5/PlayerMovement5.cs
Normal file
|
@ -0,0 +1,107 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Level5 {
|
||||
public class PlayerMovement5 : PlayerStats {
|
||||
|
||||
[Header("Shooting")]
|
||||
[SerializeField] Bullet5 bullet;
|
||||
[SerializeField] Transform shootingPos;
|
||||
|
||||
[Header("Physics")]
|
||||
[SerializeField] LayerMask groundMask;
|
||||
[SerializeField] Vector2 feetSize;
|
||||
|
||||
float _horizontalInput;
|
||||
float _xVelocity, _accelerationVelocity;
|
||||
float _currentCoyoteTime, _currentBufferTime;
|
||||
bool _grounded;
|
||||
|
||||
int _facingDirection = 1;
|
||||
|
||||
PlayerInput _playerInput;
|
||||
|
||||
[Header("Animations")]
|
||||
[SerializeField] Animator animator;
|
||||
public Animator Animator => animator;
|
||||
|
||||
public static readonly int Jump1 = Animator.StringToHash("Jump");
|
||||
static readonly int XVelocity = Animator.StringToHash("xVelocity");
|
||||
static readonly int YVelocity = Animator.StringToHash("yVelocity");
|
||||
static readonly int Grounded = Animator.StringToHash("Grounded");
|
||||
|
||||
void Awake() {
|
||||
_playerInput = new PlayerInput();
|
||||
|
||||
_playerInput.Gameplay.Horizontal.started += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.performed += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.canceled += HorizontalHandler;
|
||||
|
||||
_playerInput.Gameplay.Jump.started += Jump;
|
||||
_playerInput.Gameplay.Jump.canceled += Jump;
|
||||
|
||||
_playerInput.Gameplay.Fire.performed += Fire;
|
||||
}
|
||||
|
||||
void Jump(InputAction.CallbackContext obj) {
|
||||
if (obj.started) {
|
||||
_currentBufferTime = bufferTime;
|
||||
}else if (obj.canceled) {
|
||||
if (Rb.velocity.y < 0f) return;
|
||||
Rb.velocity = new Vector2(Rb.velocity.x, Rb.velocity.y * jumpCancellationMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
void Fire(InputAction.CallbackContext obj) {
|
||||
Bullet5 bullet5 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
|
||||
bullet5.AddForce(_facingDirection);
|
||||
}
|
||||
|
||||
void HorizontalHandler(InputAction.CallbackContext obj) {
|
||||
_horizontalInput = obj.ReadValue<float>();
|
||||
_facingDirection = _horizontalInput > 0 ? 1 : _horizontalInput < 0 ? -1 : _facingDirection;
|
||||
transform.localScale = new Vector3(_facingDirection, 1, 1);
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
_playerInput.Enable();
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
_playerInput.Disable();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
animator.SetFloat(XVelocity, Mathf.Abs(_xVelocity));
|
||||
animator.SetFloat(YVelocity, Rb.velocity.y);
|
||||
animator.SetBool(Grounded, _grounded);
|
||||
|
||||
if (_currentBufferTime > 0f && _currentCoyoteTime > 0f) {
|
||||
Rb.velocity = new Vector2(Rb.velocity.x, jumpForce);
|
||||
animator.SetTrigger(Jump1);
|
||||
|
||||
_currentBufferTime = _currentCoyoteTime = 0f;
|
||||
}
|
||||
|
||||
_currentCoyoteTime -= Time.deltaTime;
|
||||
_currentBufferTime -= Time.deltaTime;
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
_grounded = Physics2D.OverlapBox(transform.position, feetSize, 0, groundMask);
|
||||
if (_grounded && Rb.velocity.y < .1f)
|
||||
_currentCoyoteTime = coyoteTime;
|
||||
|
||||
_xVelocity = Rb.velocity.x;
|
||||
_xVelocity = Mathf.SmoothDamp(_xVelocity, _horizontalInput * speed, ref _accelerationVelocity,
|
||||
acceleration);;
|
||||
Rb.velocity = new Vector2(_xVelocity, Rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, feetSize);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 5/PlayerMovement5.cs.meta
Normal file
11
Assets/Scripts/Level 5/PlayerMovement5.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3678eb6db55eeed4cb40cc33339d70c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Level 8.meta
Normal file
8
Assets/Scripts/Level 8.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 86e2699d81c3b03418a02e82a17f2670
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
16
Assets/Scripts/Level 8/Bullet8.cs
Normal file
16
Assets/Scripts/Level 8/Bullet8.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level8 {
|
||||
public class Bullet8 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
public void AddForce(int direction) {
|
||||
Rigidbody2D rb = GetComponent<Rigidbody2D>();
|
||||
rb.velocity = Vector2.right * direction * speed;
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D other) {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 8/Bullet8.cs.meta
Normal file
11
Assets/Scripts/Level 8/Bullet8.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 07abba302fe75e04c8485e7a5ae40dcb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
48
Assets/Scripts/Level 8/Enemy8.cs
Normal file
48
Assets/Scripts/Level 8/Enemy8.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level8 {
|
||||
public class Enemy8 : MonoBehaviour {
|
||||
[SerializeField] float speed;
|
||||
|
||||
[SerializeField] LayerMask groundLayer;
|
||||
|
||||
[SerializeField] Transform sprite;
|
||||
|
||||
[Header("Flipping Pivots")]
|
||||
[SerializeField] Transform flippingPivotLeft;
|
||||
[SerializeField] Transform flippingPivotRight;
|
||||
|
||||
int _facingDirection = 1;
|
||||
Rigidbody2D _rb;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake() {
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate() {
|
||||
if (_facingDirection > 0) {
|
||||
if (Physics2D.OverlapBox(flippingPivotRight.position, flippingPivotRight.localScale, 0, groundLayer)) {
|
||||
_facingDirection = -1;
|
||||
sprite.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
}else {
|
||||
if (Physics2D.OverlapBox(flippingPivotLeft.position, flippingPivotLeft.localScale, 0, groundLayer)) {
|
||||
_facingDirection = 1;
|
||||
sprite.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
_rb.velocity = new Vector2(speed * _facingDirection, _rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
if(!flippingPivotLeft || !flippingPivotRight) return;
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
|
||||
Gizmos.DrawWireCube(flippingPivotLeft.position, flippingPivotLeft.localScale);
|
||||
Gizmos.DrawWireCube(flippingPivotRight.position, flippingPivotRight.localScale);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 8/Enemy8.cs.meta
Normal file
11
Assets/Scripts/Level 8/Enemy8.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8f8ff3b239fcea04b91b8c49085c0cdb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
21
Assets/Scripts/Level 8/EnemyWeakPoint8.cs
Normal file
21
Assets/Scripts/Level 8/EnemyWeakPoint8.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level8 {
|
||||
public class EnemyWeakPoint8 : MonoBehaviour {
|
||||
|
||||
Enemy8 _enemy;
|
||||
|
||||
void Awake() {
|
||||
_enemy = GetComponentInParent<Enemy8>();
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other) {
|
||||
if (!other.CompareTag("Player")) return;
|
||||
PlayerMovement8 player = other.GetComponent<PlayerMovement8>();
|
||||
|
||||
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
|
||||
player.Animator.SetTrigger(PlayerMovement8.Jump1);
|
||||
Destroy(_enemy.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Level 8/EnemyWeakPoint8.cs.meta
Normal file
3
Assets/Scripts/Level 8/EnemyWeakPoint8.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 07622b149a150ff4c9470ed89e7347c8
|
||||
timeCreated: 1691603524
|
16
Assets/Scripts/Level 8/PlayerFollower8.cs
Normal file
16
Assets/Scripts/Level 8/PlayerFollower8.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Level8 {
|
||||
public class PlayerFollower8 : MonoBehaviour {
|
||||
public void SetPosition(Vector3 position, bool grounded) {
|
||||
if (grounded) {
|
||||
transform.position = position;
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 pos = transform.position;
|
||||
pos.x = position.x;
|
||||
transform.position = pos;
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Level 8/PlayerFollower8.cs.meta
Normal file
3
Assets/Scripts/Level 8/PlayerFollower8.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fa9b72934e014867b4b865e119ad0f0b
|
||||
timeCreated: 1692381164
|
111
Assets/Scripts/Level 8/PlayerMovement8.cs
Normal file
111
Assets/Scripts/Level 8/PlayerMovement8.cs
Normal file
|
@ -0,0 +1,111 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Level8 {
|
||||
public class PlayerMovement8 : PlayerStats {
|
||||
|
||||
[SerializeField] PlayerFollower8 playerFollower8;
|
||||
|
||||
[Header("Shooting")]
|
||||
[SerializeField] Bullet8 bullet;
|
||||
[SerializeField] Transform shootingPos;
|
||||
|
||||
[Header("Physics")]
|
||||
[SerializeField] LayerMask groundMask;
|
||||
[SerializeField] Vector2 feetSize;
|
||||
|
||||
float _horizontalInput;
|
||||
float _xVelocity, _accelerationVelocity;
|
||||
float _currentCoyoteTime, _currentBufferTime;
|
||||
bool _grounded;
|
||||
|
||||
int _facingDirection = 1;
|
||||
|
||||
PlayerInput _playerInput;
|
||||
|
||||
[Header("Animations")]
|
||||
[SerializeField] Animator animator;
|
||||
public Animator Animator => animator;
|
||||
|
||||
public static readonly int Jump1 = Animator.StringToHash("Jump");
|
||||
static readonly int XVelocity = Animator.StringToHash("xVelocity");
|
||||
static readonly int YVelocity = Animator.StringToHash("yVelocity");
|
||||
static readonly int Grounded = Animator.StringToHash("Grounded");
|
||||
|
||||
void Awake() {
|
||||
_playerInput = new PlayerInput();
|
||||
|
||||
_playerInput.Gameplay.Horizontal.started += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.performed += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.canceled += HorizontalHandler;
|
||||
|
||||
_playerInput.Gameplay.Jump.started += Jump;
|
||||
_playerInput.Gameplay.Jump.canceled += Jump;
|
||||
|
||||
_playerInput.Gameplay.Fire.performed += Fire;
|
||||
}
|
||||
|
||||
void Jump(InputAction.CallbackContext obj) {
|
||||
if (obj.started) {
|
||||
_currentBufferTime = bufferTime;
|
||||
}else if (obj.canceled) {
|
||||
if (Rb.velocity.y < 0f) return;
|
||||
Rb.velocity = new Vector2(Rb.velocity.x, Rb.velocity.y * jumpCancellationMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
void Fire(InputAction.CallbackContext obj) {
|
||||
Bullet8 bullet8 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
|
||||
bullet8.AddForce(_facingDirection);
|
||||
}
|
||||
|
||||
void HorizontalHandler(InputAction.CallbackContext obj) {
|
||||
_horizontalInput = obj.ReadValue<float>();
|
||||
_facingDirection = _horizontalInput > 0 ? 1 : _horizontalInput < 0 ? -1 : _facingDirection;
|
||||
transform.localScale = new Vector3(_facingDirection, 1, 1);
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
_playerInput.Enable();
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
_playerInput.Disable();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
animator.SetFloat(XVelocity, Mathf.Abs(_xVelocity));
|
||||
animator.SetFloat(YVelocity, Rb.velocity.y);
|
||||
animator.SetBool(Grounded, _grounded);
|
||||
|
||||
if (_currentBufferTime > 0f && _currentCoyoteTime > 0f) {
|
||||
Rb.velocity = new Vector2(Rb.velocity.x, jumpForce);
|
||||
animator.SetTrigger(Jump1);
|
||||
|
||||
_currentBufferTime = _currentCoyoteTime = 0f;
|
||||
}
|
||||
|
||||
_currentCoyoteTime -= Time.deltaTime;
|
||||
_currentBufferTime -= Time.deltaTime;
|
||||
|
||||
playerFollower8.SetPosition(transform.position, _grounded);
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
_grounded = Physics2D.OverlapBox(transform.position, feetSize, 0, groundMask);
|
||||
if (_grounded && Rb.velocity.y < .1f)
|
||||
_currentCoyoteTime = coyoteTime;
|
||||
|
||||
_xVelocity = Rb.velocity.x;
|
||||
_xVelocity = Mathf.SmoothDamp(_xVelocity, _horizontalInput * speed, ref _accelerationVelocity,
|
||||
acceleration);;
|
||||
Rb.velocity = new Vector2(_xVelocity, Rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, feetSize);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 8/PlayerMovement8.cs.meta
Normal file
11
Assets/Scripts/Level 8/PlayerMovement8.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cd40848ae407e14418cf25c22f6f4be5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,92 +0,0 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class PlayerMovement1 : MonoBehaviour {
|
||||
|
||||
public float deathForce = 8f;
|
||||
[SerializeField] float speed = 5f;
|
||||
[SerializeField] float jumpForce = 10f;
|
||||
|
||||
[Header("Shooting")]
|
||||
[SerializeField] Bullet1 bullet;
|
||||
[SerializeField] Transform shootingPos;
|
||||
|
||||
[Header("Physics")]
|
||||
[SerializeField] LayerMask groundMask;
|
||||
[SerializeField] Vector2 feetSize;
|
||||
|
||||
float _horizontalInput;
|
||||
bool _grounded;
|
||||
|
||||
int _facingDirection = 1;
|
||||
|
||||
public Rigidbody2D Rb { get; private set; }
|
||||
|
||||
PlayerInput _playerInput;
|
||||
|
||||
[Header("Animations")]
|
||||
[SerializeField] Animator animator;
|
||||
public Animator Animator => animator;
|
||||
|
||||
public static readonly int Jump1 = Animator.StringToHash("Jump");
|
||||
static readonly int XVelocity = Animator.StringToHash("xVelocity");
|
||||
static readonly int YVelocity = Animator.StringToHash("yVelocity");
|
||||
static readonly int Grounded = Animator.StringToHash("Grounded");
|
||||
|
||||
void Awake() {
|
||||
Rb = GetComponent<Rigidbody2D>();
|
||||
|
||||
_playerInput = new PlayerInput();
|
||||
|
||||
_playerInput.Gameplay.Horizontal.started += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.performed += HorizontalHandler;
|
||||
_playerInput.Gameplay.Horizontal.canceled += HorizontalHandler;
|
||||
|
||||
_playerInput.Gameplay.Jump.performed += Jump;
|
||||
|
||||
_playerInput.Gameplay.Fire.performed += Fire;
|
||||
}
|
||||
|
||||
void Jump(InputAction.CallbackContext obj) {
|
||||
if (!_grounded) return;
|
||||
Rb.velocity = new Vector2(Rb.velocity.x, jumpForce);
|
||||
animator.SetTrigger(Jump1);
|
||||
}
|
||||
|
||||
void Fire(InputAction.CallbackContext obj) {
|
||||
Bullet1 bullet1 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
|
||||
bullet1.AddForce(_facingDirection);
|
||||
}
|
||||
|
||||
void HorizontalHandler(InputAction.CallbackContext obj) {
|
||||
_horizontalInput = obj.ReadValue<float>();
|
||||
_facingDirection = _horizontalInput > 0 ? 1 : _horizontalInput < 0 ? -1 : _facingDirection;
|
||||
transform.localScale = new Vector3(_facingDirection, 1, 1);
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
_playerInput.Enable();
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
_playerInput.Disable();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
animator.SetFloat(XVelocity, Mathf.Abs(_horizontalInput * speed));
|
||||
animator.SetFloat(YVelocity, Rb.velocity.y);
|
||||
animator.SetBool(Grounded, _grounded);
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
_grounded = Physics2D.OverlapBox(transform.position, feetSize, 0, groundMask);
|
||||
Rb.velocity = new Vector2(_horizontalInput * speed, Rb.velocity.y);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, feetSize);
|
||||
}
|
||||
}
|
36
Assets/Scripts/PlayerStats.cs
Normal file
36
Assets/Scripts/PlayerStats.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class PlayerStats : MonoBehaviour{
|
||||
[HideInInspector] public float deathForce = 8f;
|
||||
[HideInInspector] public float speed = 5f;
|
||||
[HideInInspector] public float jumpForce = 10f;
|
||||
[HideInInspector] public float acceleration = 1f;
|
||||
[HideInInspector] public float jumpCancellationMultiplier = .5f;
|
||||
[HideInInspector] public float coyoteTime = .1f;
|
||||
[HideInInspector] public float bufferTime = .1f;
|
||||
|
||||
public Rigidbody2D Rb { get; private set; }
|
||||
|
||||
void Start() {
|
||||
Rb = GetComponent<Rigidbody2D>();
|
||||
|
||||
BalanceCanvas.instance.sliderChangedCallback += RefreshStats;
|
||||
RefreshStats();
|
||||
}
|
||||
|
||||
void OnDestroy() {
|
||||
BalanceCanvas.instance.sliderChangedCallback -= RefreshStats;
|
||||
}
|
||||
|
||||
void RefreshStats() {
|
||||
deathForce = PlayerPrefs.GetFloat(nameof(deathForce), deathForce);
|
||||
speed = PlayerPrefs.GetFloat(nameof(speed), speed);
|
||||
jumpForce = PlayerPrefs.GetFloat(nameof(jumpForce), jumpForce);
|
||||
acceleration = PlayerPrefs.GetFloat(nameof(acceleration), acceleration);
|
||||
jumpCancellationMultiplier = PlayerPrefs.GetFloat(nameof(jumpCancellationMultiplier), jumpCancellationMultiplier);
|
||||
Rb.gravityScale = PlayerPrefs.GetFloat(nameof(Rb.gravityScale), Rb.gravityScale);
|
||||
coyoteTime = PlayerPrefs.GetFloat(nameof(coyoteTime), coyoteTime);
|
||||
bufferTime = PlayerPrefs.GetFloat(nameof(bufferTime), bufferTime);
|
||||
}
|
||||
}
|
3
Assets/Scripts/PlayerStats.cs.meta
Normal file
3
Assets/Scripts/PlayerStats.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b65a2e11366c4b6683fb4fc53465fb2b
|
||||
timeCreated: 1692370022
|
Loading…
Add table
Add a link
Reference in a new issue