Initial
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BoxesController : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.tag == "Player")
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ade875a254231c4d8c43cacc7b27bfb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Animator animator;
|
||||
[SerializeField]
|
||||
private float MovementSpeed = 1.5f;
|
||||
[SerializeField]
|
||||
private LayerMask ladderLayer;
|
||||
[SerializeField]
|
||||
private LayerMask groundLayer;
|
||||
[SerializeField]
|
||||
private float distance;
|
||||
private bool _isOnLadder;
|
||||
private Rigidbody2D _body;
|
||||
private CapsuleCollider2D _capsule;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_body = GetComponent<Rigidbody2D>();
|
||||
_capsule= GetComponent<CapsuleCollider2D>();
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
float moveX = Input.GetAxisRaw("Horizontal");
|
||||
animator.SetFloat("Horizontal", moveX);
|
||||
float moveY = 0;
|
||||
|
||||
var groundCheck = Physics2D.CapsuleCast(_capsule.bounds.center,_capsule.bounds.size,CapsuleDirection2D.Vertical,0f, Vector2.down, .1f,groundLayer);
|
||||
|
||||
if (groundCheck || _isOnLadder)
|
||||
{
|
||||
var ladderCheck = Physics2D.CapsuleCast(_capsule.bounds.center, _capsule.bounds.size, CapsuleDirection2D.Vertical, 0f, Vector2.down, .1f, ladderLayer);
|
||||
if (ladderCheck)
|
||||
{
|
||||
_isOnLadder = true;
|
||||
moveY = Input.GetAxisRaw("Vertical");
|
||||
if(moveY> 0)
|
||||
{
|
||||
if(!Physics2D.CapsuleCast(_capsule.bounds.center, _capsule.bounds.size, CapsuleDirection2D.Vertical, 0f, Vector2.up, .1f, ladderLayer))
|
||||
{
|
||||
moveY= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_isOnLadder = false;
|
||||
}
|
||||
_body.velocity = new Vector2(moveX * MovementSpeed, moveY * MovementSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (_isOnLadder)
|
||||
{
|
||||
|
||||
_body.gravityScale = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_body.gravityScale = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c83b0150e991b443858a82f5a1eea57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user