62 lines
1.2 KiB
C#
62 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
public class UnitCtrl : MonoBehaviour
|
|
{
|
|
public UnitInfo unit;
|
|
public Animator anim;
|
|
public GameObject defensObj;
|
|
bool isAttack;
|
|
|
|
public bool isEnemy;
|
|
|
|
private void Start()
|
|
{
|
|
if(isEnemy)
|
|
defensObj.tag = "enemy";
|
|
else
|
|
defensObj.tag = "player";
|
|
}
|
|
private void Update()
|
|
{
|
|
if (isAttack)
|
|
{
|
|
anim.SetTrigger("att");
|
|
}
|
|
else
|
|
{
|
|
transform.position += Vector3.left * unit.moveSpeed * Time.deltaTime * (isEnemy ? 1 : -1);
|
|
}
|
|
|
|
}
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
{
|
|
if (isEnemy)
|
|
{
|
|
if (collision.gameObject.CompareTag("player"))
|
|
{
|
|
Debug.Log("Ãæµ¹");
|
|
isAttack = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (collision.gameObject.CompareTag("enemy"))
|
|
{
|
|
Debug.Log("Ãæµ¹");
|
|
isAttack = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
//private void OnTriggerExit2D(Collider2D collision)
|
|
//{
|
|
// Debug.Log("Ãæµ¹Á¾·á");
|
|
// isAttack = false;
|
|
//}
|
|
|
|
|
|
}
|