in progress bug movement

This commit is contained in:
2020-01-31 23:03:38 -05:00
parent 5f521efcd3
commit 111bb5e27e
16 changed files with 530 additions and 599 deletions

View File

@@ -0,0 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class LayerNames
{
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f390aa3a3cda63143bdb8159cf98b63d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -7,9 +7,10 @@ public class Player : MonoBehaviour
[SerializeField] private float runSpeed = 10f;
[SerializeField] private float jumpSpeed = 10f;
[SerializeField] private float runFasterFactor = 1.5f;
[SerializeField] GameObject ground;
Rigidbody2D rigidbody;
private Rigidbody2D rigidbody;
private string enemiesLayerName => "Enemies";
private string groundLayerName => "Ground";
private void Start()
{
@@ -18,6 +19,7 @@ public class Player : MonoBehaviour
private void Update()
{
Debug.Log(HasEncounteredEnemy());
MovePlayer();
}
@@ -29,7 +31,7 @@ public class Player : MonoBehaviour
private void Jump()
{
var playerOnGround = rigidbody.IsTouching(ground.GetComponent<CompositeCollider2D>());
var playerOnGround = rigidbody.IsTouchingLayers(LayerMask.GetMask(groundLayerName));
// Jump
if (Input.GetKey(KeyCode.Space) && playerOnGround)
@@ -59,6 +61,10 @@ public class Player : MonoBehaviour
{
rigidbody.velocity = new Vector2(actualRunSpeed * -1, rigidbody.velocity.y);
}
}
private bool HasEncounteredEnemy()
{
return rigidbody.IsTouchingLayers(LayerMask.GetMask(enemiesLayerName));
}
}