개발일기
유니티#2 prefap 본문
//PlayerSkill.cs
public class PlayerSkill : MonoBehaviour //Player 오브젝트 연결
{
public GameObject skillPrefab;
private GameObject slash1;
private PlayerMove playerMove;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
playerMove = GetComponent<PlayerMove>();
if (skillPrefab == null)
{
Debug.LogError("Skill Prefab is not assigned!");
}
}
// ...
}
PlayerSkill.cs void Update()
# void Update
Vector3 spawnPosition = transform.position + new Vector3((direction ? 1 : -1), 0, 0);
GameObject skillObject = Instantiate(skillPrefab, spawnPosition, Quaternion.identity); // 여기서 생성
Vector3 scale = skillObject.transform.localScale;
scale.x *= direction ? 1 : -1; // 방향에 따라 X축 반전
skillObject.transform.localScale = scale;
Animator skillAnimator = skillObject.GetComponent<Animator>();
if (skillAnimator != null) {
skillAnimator.SetTrigger("PlaySlash");
} else {
Debug.LogError("Animator not found on skill prefab!");
}
// 스킬 자동 삭제 (선택 사항)
Destroy(skillObject, 1f); // 1초 뒤 삭제
오브젝트 생성은 프리팹이라는 걸 쓴다나보다
약간 밀키트 같은 느낌이다
참고로 애니메이션이 느리면 한 사이클이 다 끝나고도 처음부분이 중복되어서 나오는데
애니메이션 속도를 빠르게 하니 사라졌다
이제 해야할 거
- 스킬 모듈화
- Enemy HP 구현
- 공격 상호작용
'Unity' 카테고리의 다른 글
| 유니티#6 ScriptableObject (0) | 2024.12.26 |
|---|---|
| 유니티#5 private 변수 참조 (0) | 2024.12.26 |
| 유니티#4 스크립트 정리 (2) | 2024.12.26 |
| 유니티#3 early return, 모듈화 초입 (4) | 2024.12.25 |
| 유니티#1 animator (2) | 2024.12.23 |