https://github.com/Tealss/Baby
오늘부터 시작된 팀 프로젝트
아이작을 모티브로한 아기작을 만들거에용
이제 저같은 경우 전투쪽 몬스터생성과 피해체력관리 퍼마데스(죽었을때 나오는 ui) 드랍아이템 등
손을 볼 예정입니다.
몬스터 라는 객체를 만들고 그 안에 체력과 피해를 조절한다음 드랍아이템을 만들어서 제공할거에용
퍼마데스는 아마 캐릭터 만드시는 분껄 참고해서 할예정이고용
이렇게 한번 만들어 봤는데 수정사항이 정말 많습니다
저번에 한 프로젝트의 보스코드를 가져와서 조금 수정한거거든요
내일 아마 다듬어서 최대한 구현해보도록 하겠습니다!!!!!!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.InputSystem.XR;
public class Monster : MonoBehaviour
{
private Rigidbody2D _rigidbody;
private Animator _anim;
private Rigidbody2D _target;
public Gameobject Player1;
public Slider mySlider;
private int _MaxHp;
private int _Hp;
private float _Speed;
private bool _IsHit = false;
private bool _IsDelay = false;
public void Init(int hp, float speed)
{
_rigidbody = GetComponent<Rigidbody2D>();
_anim = GetComponent<Animator>();
_target = Gameobject; //플레이어 추격
_MaxHp = hp;
_Hp = hp;
_Speed = speed;
mySlider.value = _Hp / _MaxHp;
_rigidbody.velocity = Vector2.zero;
}
void FixedUpdate()
{
if (_IsHit)
{
_rigidbody.velocity = (_target.position - _rigidbody.position) * -2;
}
else
{
_rigidbody.velocity = (_target.position - _rigidbody.position) * _Speed;
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("SnowBall")) //피격 아이템
{
_anim.SetTrigger("Hit");
_IsHit = true;
StartCoroutine(Hit());
_Hp--;
mySlider.value = (float)_Hp / (float)_MaxHp;
if (_Hp <= 0)
{
gameObject.SetActive(false);
}
}
if (collision.CompareTag("Player")) //플레이어에 닿으면 체력이 닿는 코드
{
if (!_IsDelay)
{
_IsDelay = true;
//AudioManager.I.PlaySfx(AudioManager.Sfx.Hit);
//HpController.I.CallHpAdd(-15f);
StartCoroutine(Delay());
}
}
}
IEnumerator Delay()
{
yield return new WaitForSeconds(0.5f);
_IsDelay = false;
}
IEnumerator Hit()
{
yield return new WaitForSeconds(0.1f);
_IsHit = false;
}
}