'유니티/스크립트'에 해당되는 글 123건

  1. 2014.02.02 유니티 c# 의 딜리게이트와 이벤트 사용 방법
  2. 2014.02.01 유니티 전용 싱글톤 패턴
  3. 2014.01.30 Rigidbody 2D
  4. 2014.01.29 점프게임 관련 발판 생성 스크립트
  5. 2014.01.29 유니티 점프 게임 구현시 카메라 이동 (2)
  6. 2014.01.29 [펌] 물리엔진을 사용하지 않고 점프 구현 하기
  7. 2014.01.29 플레이어 점프 구현 하기 (레이캐스트 사용) (1)
  8. 2014.01.29 GUIText 사용 득점 화면 표시 (점수가 위로 이동하면서 사라지는 효과)
  9. 2014.01.29 GUIText를 사용해서 플레이어 HP 표현 혹은 적 공격 시 점수 표현
  10. 2014.01.29 화면 밖을 벗어나는 오브젝트 삭제 하기

유니티 c# 의 딜리게이트와 이벤트 사용 방법

|
OnEnbale - 개체 활성화 및 활성화될 때 호출됩니다.
OnDisable 개체 비활성화 및 비활성화될 때 호출됩니다.

객체가 활성화 될때 이벤트에 딜리게이트를 더하고, 비활성화될때는 이벤트에 해당 딜리게이티를 제거 해줍니다.





Trackback 0 And Comment 0

유니티 전용 싱글톤 패턴

|

유니티 내의 FindObjectOfType함수를 사용하는 싱글톤 패턴


Trackback 0 And Comment 0

Rigidbody 2D

|

Rigidbody 2D

Rigidbody 2D component places an object under the control of the physics engine. Many concepts familiar from the standard Rigidbody component carry over to Rigidbody 2D, with the difference that in 2D, objects can only move in the XY plane and can only rotate on an axis perpendicular to that plane.




MassMass of the rigidbody.
Linear DragDrag coefficient affecting positional movement.
Angular DragDrag coefficient affecting rotational movement.
Gravity ScaleDegree to which the object is affected by gravity.
Fixed Angle

리지드 바디에 힘을 가할때 회전을 적용할지 여부 체크하면 회전이 안됨

Is KinematicIs the rigidbody moved by forces and collisions?
InterpolateHow the object's movement is interpolated between physics updates (useful when motion tends to be jerky).
NoneNo movement smoothing is applied.
InterpolateMovement is smoothed based on the object's positions in previous frames.
ExtrapolateMovement is smoothed based on an estimate of its position in the next frame.
Sleeping ModeHow the object "sleeps" to save processor time when it is at rest.
Never SleepSleeping is disabled.
Start AwakeObject is initially awake.
Start AsleepObject is initially asleep but can be woken by collisions.
Collision DetectionHow collisions with other objects are detected.
DiscreteA collision is registered only if the object's collider is in contact with another during a physics update.
ContinuousA collision is registered if the object's collider appears to have contacted another between updates.

Details

Adding a Rigidbody 2D allows a sprite to be moved in a physically convincing way by applying forces from the scripting API. When the appropriate collider component is also attached to the sprite object, it will be affected by collisions with other moving objects. Using physics simplifies many common gameplay mechanics and allows for realistic, emergent behaviour with minimal coding.

Colliders

Colliders define an approximate shape for an object that will be used by the physics engine to determine collisions with other objects. The collider types that can be used with Rigidbody 2D are the Circle Collider 2D, Box Collider 2D and Polygon Collider 2D - see the pages for these component for further details.

Kinematic Rigidbodies

The Is Kinematic setting switches off the physical behaviour of the Rigidbody 2D so that it will not react to gravity and collisions. This is typically used to keep an object under non-physical script control most of the time but then switch to physics in a particular situation. For example, a player might normally move by walking (better handled without physics) but then get catapulted into the air by an explosion or strike. Physics can be used to create the catapulting effect if you switch off ''Is Kinematic" just before applying a large force to the object.

Page last updated: 2013-08-15




Rigidbody 2D

Rigidbody 2D component places an object under the control of the physics engine. Many concepts familiar from the standard Rigidbody component carry over to Rigidbody 2D, with the difference that in 2D, objects can only move in the XY plane and can only rotate on an axis perpendicular to that plane.




MassMass of the rigidbody.
Linear DragDrag coefficient affecting positional movement.
Angular DragDrag coefficient affecting rotational movement.
Gravity ScaleDegree to which the object is affected by gravity.
Fixed AngleCan the rigidbody rotate when forces are applied?
Is KinematicIs the rigidbody moved by forces and collisions?
InterpolateHow the object's movement is interpolated between physics updates (useful when motion tends to be jerky).
NoneNo movement smoothing is applied.
InterpolateMovement is smoothed based on the object's positions in previous frames.
ExtrapolateMovement is smoothed based on an estimate of its position in the next frame.
Sleeping ModeHow the object "sleeps" to save processor time when it is at rest.
Never SleepSleeping is disabled.
Start AwakeObject is initially awake.
Start AsleepObject is initially asleep but can be woken by collisions.
Collision DetectionHow collisions with other objects are detected.
DiscreteA collision is registered only if the object's collider is in contact with another during a physics update.
ContinuousA collision is registered if the object's collider appears to have contacted another between updates.

Details

Adding a Rigidbody 2D allows a sprite to be moved in a physically convincing way by applying forces from the scripting API. When the appropriate collider component is also attached to the sprite object, it will be affected by collisions with other moving objects. Using physics simplifies many common gameplay mechanics and allows for realistic, emergent behaviour with minimal coding.

Colliders

Colliders define an approximate shape for an object that will be used by the physics engine to determine collisions with other objects. The collider types that can be used with Rigidbody 2D are the Circle Collider 2D, Box Collider 2D and Polygon Collider 2D - see the pages for these component for further details.

Kinematic Rigidbodies

The Is Kinematic setting switches off the physical behaviour of the Rigidbody 2D so that it will not react to gravity and collisions. This is typically used to keep an object under non-physical script control most of the time but then switch to physics in a particular situation. For example, a player might normally move by walking (better handled without physics) but then get catapulted into the air by an explosion or strike. Physics can be used to create the catapulting effect if you switch off ''Is Kinematic" just before applying a large force to the object.

Page last updated: 2013-08-15

Trackback 0 And Comment 0

점프게임 관련 발판 생성 스크립트

|

점프게임 관련 아이템 생성 스크립트.

점프게임 구현시 발판을 플레이어가 점프할때 마다 위에서 계속해서 생성해줘야된다.

플레이어의 점프 높이와 간격등을 고려해서 구현해야됨.

프리팹을 생성후. 일정높이에서 spPoint를 만들고 spPoint의 위치에서 생성해준다.

그리고 그 전 생성 위치와 비교를 해서 생성해준다.

 


Trackback 0 And Comment 0

유니티 점프 게임 구현시 카메라 이동

|

유니티 점프 게임 구현시 카메라 이동.

플레이어가 점프를 하면 카메라는 일정 거리만큼 이동되고 정지한다.

플레이어가 떨어질때는 카메라의 이동은 없다.


플레이어 스크립트의 update에 집어넣자



Trackback 0 And Comment 2
  1. Favicon of https://bangdung.tistory.com BlogIcon 감말랭이 2014.09.29 01:57 신고 address edit & del reply

    유니티 게임만드는 학생인데용 매번 검색할때마다 뜨는 티스토리가 여기더라구요ㅎㅎㅎ
    정말 많은 도움이 되고 있어서 댓글 남겨염! 정말 멋지고 감사해요!!

[펌] 물리엔진을 사용하지 않고 점프 구현 하기

|

출처 : http://blog.naver.com/PostView.nhn?blogId=predev&Redirect=View&logNo=130178007397&categoryNo=71&isAfterWrite=true



Trackback 0 And Comment 0

플레이어 점프 구현 하기 (레이캐스트 사용)

|

플레이어가 점프를 할때 땅위에서만 점프가 가능하도록 해야됩니다.

플레이어 아래가 땅인지 판단해서 땅이면 점프가 간으하도록 하는 스크립트 입니다.

플레이어는 리지드바드가 적용되있는 상태고 . 물리를 사용하기 때문에 FixedUpdate 에서 처리해줍니다.

기존 방식과 달리 리지드바디의 AddForce 및 velocity를 사용합니다.





Debug.DrawRay(transform.position, Vector3.down * 0.9f, Color.red); 를 사용해서 레이 캐스트 기즈모를 그려줍니다.
그리고 미리 지정된 Tag 값이 Ground면 점프 버튼을 눌렀을때 점프가 가능하도록 합니다.
물리를 사용하면 FixedUpdate 에서 처리해줍니다.





Trackback 0 And Comment 1
  1. 2014.11.21 23:40 address edit & del reply

    움직이면서 점프는 어떻게 하나요?

GUIText 사용 득점 화면 표시 (점수가 위로 이동하면서 사라지는 효과)

|

보통 게임에서 득점을 표시할때 위로 점수가 올라가면서 사라지는 효과를 많이 쓰인다.

그 효과는 GUIText를 생성하고 아래 스크립트를 붙이면 그대로 사용할수 있다.





ScoreDelay 시간을 늘려주면 화면에서 사라지는 시간이 늦춰진다.





Trackback 0 And Comment 0

GUIText를 사용해서 플레이어 HP 표현 혹은 적 공격 시 점수 표현

|

2D 게임에서 플레이어 점수를 숫자로 표현한다던가. 적을 공격했을시 공격 성공시 적위에 숫자로 점수를 표현하고 싶을때가 있습니다.

NGUI 나 다른 에셋을 사용하지 않고 GUIText만을 사용하여 점수등을 표현할수 있습니다.

아래 스크립트는 1초마다 플레어의 HP가 깍이고 플레이어 머리 위에 GUIText로 HP를 표현하는 스크립트입니다.



카메라 설정






GUIText(이름 HP) 프리팹 설정







큐브생성 이름 Player 변경 -> CsPlayer 스크립트 할당




GUIText의 경우 뷰포트 좌표를 사용하므로 플레이어 좌표를 받아서 (플레이어 좌표는 월드좌표) 뷰포트 좌표로 변형하는 스크립트가 필요합니다.









Trackback 0 And Comment 0

화면 밖을 벗어나는 오브젝트 삭제 하기

|

런 게임이나 점프 게임 액션 게임등 카메라를 벗어나는 오브젝트들은 메모리 문제로 삭제해야 됩니다.

이런 게임들을 개발할때는 카메라 이동 방식이 두가지 가 있습니다.

첫번째는 캐릭터가 카메라를 쫓아다니는 방법(실제로 캐릭터의 월드 좌표가 변하는 방법)

두번째는 카메라는 고정되고 물체가 캐릭터로 이동하는 방법(실제론 캐릭터의 월드 좌표는 변하지 않는 방법)


캐릭터의 월드좌표가 변할시에는

transform.position를 이용해서 메모리에서 삭제하는 방법을 사용할수 없습니다.

월드좌표가 지속적으로 변하기 때문에 사용할수없습니다.


그러므로 캐릭터의 화면 밖으로 나갔는지 검사할 수 있는 스크립트가 필요합니다.

월드좌표를 스크린좌표로 변형하면 이런문제가 사라집니다.-> 스크린 좌표는 항상 일정하기 때문에


아래 스크립트 입니다.


위 스크립트는 종스크롤 슈팅게임에서 비행기가 계속해서 앞으로 이동하는 스크립트에서 적 스크립트가 아래쪽으로 이동하면 적 오브젝트를 제거하는 스크립트입니다. 당연히 카메라는 주인공 오브젝트에 자식 오브젝트로 할당된 상태입니다.


Trackback 0 And Comment 0
prev | 1 | ··· | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ··· | 13 | next