in progress bug movement
This commit is contained in:
8
Assets/Scripts/LayerNames.cs
Normal file
8
Assets/Scripts/LayerNames.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class LayerNames
|
||||
{
|
||||
|
||||
}
|
||||
11
Assets/Scripts/LayerNames.cs.meta
Normal file
11
Assets/Scripts/LayerNames.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f390aa3a3cda63143bdb8159cf98b63d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user