added Enemy

This commit is contained in:
2023-06-25 17:58:03 +03:00
parent e972ae1d8c
commit 57d12623f6
3 changed files with 34 additions and 6 deletions
+1 -2
View File
@@ -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();
+17 -2
View File
@@ -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);
}
}
+16 -2
View File
@@ -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()
{