using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WayPoint : MonoBehaviour
{
[SerializeField] GameObject TowerPrefab;
[SerializeField] bool isPlaceable = true;
void OnMouseDown()
{
if (isPlaceable)
{
Instantiate(TowerPrefab, transform.position, Quaternion.identity);
isPlaceable = false;
}
}
}
바닥 타일에 박스콜라이더랑 스크립트에 isplaceable이 체크(true)되어있어야 디펜스타워를 설치할 수 있음.
중복설치는 못하게끔 한번 프리팹 소환하고나서 isplaceable = false로 바꿈
@ 방어타워가 적 추적, 바라보기
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyTargeting : MonoBehaviour
{
// 바라볼 타워오브젝트(프리팹) 설정
[SerializeField] GameObject traceTower;
Transform target;
void Start()
{
// 적의 위치 찾기
target = FindObjectOfType<EnemyMover>().transform;
}
void Update()
{
TraceEnemy();
}
private void TraceEnemy()
{
// 적 바라보기
transform.LookAt(target);
}
}
방어 타워 프리팹에 맨위에다가 스크립트를 추가하고 적을 바라볼 타워의 상단부(BallistaTopMesh)를 넣어주고 실행한다.
유니티 길찾기 알고리즘 (1) | 2024.09.10 |
---|---|
유니티 그리드 적 소환하기 (1) | 2024.09.05 |
유니티 코루틴 (1) | 2024.09.04 |
유니티 그리드 시스템 적 움직이기 (0) | 2024.09.04 |
유니티 편집모드에서 오브젝트 이름 바꾸기 (0) | 2024.09.04 |