'2014/02/17'에 해당되는 글 4건
- 2014.02.17 특정위치 아래로 이동하는 함수 - Lerp 사용
- 2014.02.17 캐릭터 체력 바 생성하기 (1)
- 2014.02.17 Transform.TransformDirection
- 2014.02.17 타워에서 가까운 적을 판별 하는 스크립트
사용법
StartCoroutine( MoveDown(transform, 0.2f, 0.2f));
첫번째 인자 현재 트랜스폼
두번째 인자 이동 거리, 세번째 인자 이동 속도
'유니티 > 스크립트' 카테고리의 다른 글
| 가까운 위치 순으로 정렬하기 (0) | 2014.02.27 |
|---|---|
| 재귀함수 예 (0) | 2014.02.25 |
| 특정위치 아래로 이동하는 함수 - Lerp 사용 (0) | 2014.02.17 |
| 캐릭터 체력 바 생성하기 (1) | 2014.02.17 |
| Transform.TransformDirection (0) | 2014.02.17 |
| 타워에서 가까운 적을 판별 하는 스크립트 (0) | 2014.02.17 |
Trackback 0 And
Comment 0
GUITexture 를 사용하여 체력바를 표시한다.
GUITexture 두장을 사용하여 하나는 체력바 배경으로 만들고 하나는 줄어드는 체력바를 표시함.
그리고 그것을 프리팹으로 만들어준다.
몬스터에 해당 스크립트를 붙이고
체력을 설정해주고 위에서 만든 프리팹을 붙여주면 된다.
'유니티 > 스크립트' 카테고리의 다른 글
| 재귀함수 예 (0) | 2014.02.25 |
|---|---|
| 특정위치 아래로 이동하는 함수 - Lerp 사용 (0) | 2014.02.17 |
| 캐릭터 체력 바 생성하기 (1) | 2014.02.17 |
| Transform.TransformDirection (0) | 2014.02.17 |
| 타워에서 가까운 적을 판별 하는 스크립트 (0) | 2014.02.17 |
| 적이 메인카메라 쪽 바라보게 하기 (0) | 2014.02.16 |
Trackback 0 And
Comment 1
function TransformDirection (direction : Vector3) : Vector3
Description
변환 direction 지역 공간에서 전체 공간.
이 작업은 스케일이나 변환의 위치에 의해 영향을 받지 않는다 반환되는 벡터는 같은 길이를 갖는다 direction.
C#
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Transform cam = Camera.main.transform;
public Vector3 cameraRelativeRight = cam.TransformDirection(Vector3.right);
void Awake() {
rigidbody.AddForce(cameraRelativeRight * 10);
}
}
using System.Collections;
public class example : MonoBehaviour {
public Transform cam = Camera.main.transform;
public Vector3 cameraRelativeRight = cam.TransformDirection(Vector3.right);
void Awake() {
rigidbody.AddForce(cameraRelativeRight * 10);
}
}
'유니티 > 스크립트' 카테고리의 다른 글
| 특정위치 아래로 이동하는 함수 - Lerp 사용 (0) | 2014.02.17 |
|---|---|
| 캐릭터 체력 바 생성하기 (1) | 2014.02.17 |
| Transform.TransformDirection (0) | 2014.02.17 |
| 타워에서 가까운 적을 판별 하는 스크립트 (0) | 2014.02.17 |
| 적이 메인카메라 쪽 바라보게 하기 (0) | 2014.02.16 |
| 플레이어 가속도 주는 함수. (0) | 2014.02.13 |
Trackback 0 And
Comment 0
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





