added Enemy
This commit is contained in:
@@ -29,12 +29,11 @@ public class Character : MonoBehaviour
|
||||
{
|
||||
var groundCheck = Physics2D.BoxCast(_boxCollider.bounds.center, _boxCollider.bounds.size, 0f, Vector2.down, .1f, groundLayer);
|
||||
|
||||
float h_movement=0;
|
||||
float v_movement=0;
|
||||
if (groundCheck || _isOnLadder)
|
||||
{
|
||||
_isFall = false;
|
||||
h_movement=inputHorizontal ;
|
||||
float h_movement = inputHorizontal;
|
||||
if (h_movement > 0 && !_facingRight)
|
||||
{
|
||||
FlipCharacter();
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static UnityEditor.Searcher.SearcherWindow.Alignment;
|
||||
|
||||
public class EnemyAI :Character
|
||||
{
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float horizontal = 0;
|
||||
float vertical = 0;
|
||||
if (Mathf.Abs(Player.Instance.transform.position.x - transform.position.x)>0.5f)
|
||||
{
|
||||
horizontal = Player.Instance.transform.position.x - transform.position.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
vertical = Player.Instance.transform.position.y - transform.position.y;
|
||||
}
|
||||
base.MoveTo(horizontal, vertical);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,24 @@ using UnityEngine;
|
||||
|
||||
public class Player : Character
|
||||
{
|
||||
|
||||
|
||||
private int _totalCoins = 0;
|
||||
private bool _hasKey = false;
|
||||
public static Player Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
if (Instance != null)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
Debug.Log("There's more than one player instance");
|
||||
return;
|
||||
}
|
||||
PlayerPrefs.SetString("lastExitName", string.Empty);
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
|
||||
public void AddCoin()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user