InvokeRepeating 함수는 반복해서 첫번째 인자에 전달된 함수를 호출하는 API입니다.
두번째 인자는 첫 함수를 언제 호출할지 결정되는 인자이며 세번째 인자는 얼마나 자주 반복할지 결정되는 인자입니다.
위 스크립트에서는 0초만에 함수를 호출하고 1초마다 함수를 반복해주는 스크립트입니다.
Update 문에서는 DrawLine을 그려주어서 잘 판별되는지 파악하고
getClosestEnemy 함수에서는 해당되는 태그를 찾아서( 이 스크립트에서는 enemyAim) taggedEnemys 변수에 집어 넣고 for문을 돌려주어서
타워의 위치에서 적의 위치를 판별하여 sqrMagnitude로 벡터의 길이를 구해줍니다. 그 길이가 3.0 보다 작을때는 해당적의 트랜스폼을 저장하고 거리또한 저장해줍니다.
그리고 마지막으로 타겟에 변수를 저장해줍니다.
Vector3.sqrMagnitude
var sqrMagnitude: float;
Description
Returns the squared length of this vector (Read Only).
The magnitude of a vector
v is calculated as Mathf.Sqrt(Vector3.Dot(v, v)). However, the Sqrt calculation is quite complicated and takes longer to execute than the normal arithmetic operations. Calculating the squared magnitude instead of using themagnitude property is much faster - the calculation is basically the same only without the slow Sqrt call. If you are using magnitudes simply to compare distances, then you can just as well compare squared magnitudes against the squares of distances since the comparison will give the same result.See Also: magnitude.// detects when the other transform is closer than closeDistance // this is faster than using Vector3.magnitude var other : Transform; var closeDistance = 5.0; function Update() { if (other) { var offset = other.position - transform.position; var sqrLen = offset.sqrMagnitude; // square the distance we compare with if( sqrLen < closeDistance*closeDistance ) print ("The other transform is close to me!"); } }
'유니티 > 스크립트' 카테고리의 다른 글
| 캐릭터 체력 바 생성하기 (1) | 2014.02.17 |
|---|---|
| Transform.TransformDirection (0) | 2014.02.17 |
| 타워에서 가까운 적을 판별 하는 스크립트 (0) | 2014.02.17 |
| 적이 메인카메라 쪽 바라보게 하기 (0) | 2014.02.16 |
| 플레이어 가속도 주는 함수. (0) | 2014.02.13 |
| Vector3.Slerp 두 벡터 사이의 곡선 이동 (1) | 2014.02.06 |
Trackback 0 And
Comment 0
y축으로만 회전할수 있도록 x,z 값은 0으로 만들어주고 Lookat함수를 사용해서 카메라를 바라보게함
'유니티 > 스크립트' 카테고리의 다른 글
| Transform.TransformDirection (0) | 2014.02.17 |
|---|---|
| 타워에서 가까운 적을 판별 하는 스크립트 (0) | 2014.02.17 |
| 적이 메인카메라 쪽 바라보게 하기 (0) | 2014.02.16 |
| 플레이어 가속도 주는 함수. (0) | 2014.02.13 |
| Vector3.Slerp 두 벡터 사이의 곡선 이동 (1) | 2014.02.06 |
| 자식오브젝트에서 부모 오브젝트 스크립트 실행 (0) | 2014.02.06 |
Trackback 0 And
Comment 0
코사인 90도는 0
코사인 0도는 1
사인 90도는 1
사인 0도는 0
'유니티 > Note' 카테고리의 다른 글
| 유니티 광고 수익 (0) | 2014.02.18 |
|---|---|
| 유니티 개발 시작 (0) | 2014.02.18 |
| 삼각함수 관련 (0) | 2014.02.16 |
| 벡터 (0) | 2014.02.16 |
| 메카닉 관련 유니티 제공 에셋 (0) | 2014.02.14 |
| 유니티 2D 배경에 카메라 맞추기 (0) | 2014.02.04 |
Trackback 0 And
Comment 0


