Some things
This commit is contained in:
parent
6ba30e430e
commit
e4cc23e7f0
119 changed files with 70085 additions and 682 deletions
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:
|
Loading…
Add table
Add a link
Reference in a new issue