Version: 5.3 (switch to 5.4b)
언어English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

MonoBehaviour.OnCollisionStay(Collision)

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

닫기

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

닫기

취소

Switch to Manual

파라미터

other The Collision data associated with this collision.

Description

OnCollisionStay 는 collider/rigidbody가 모든 rigidbody/collider와의 접촉에 대해 매 프레임마다 한번씩 호출됩니다.

In contrast to OnTriggerStay, OnCollisionStay is passed the Collision class and not a Collider. Collision에는 접촉점, 충돌한 속도 등의 정보가 포함되어 있습니다. 이 함수의 collisionInfo를 사용하지 않으면 collisionInfo 파라미터를 생략함으로써 불필요한 계산을 피할 수 있습니다. Notes: Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached. Collision events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions. Collision stay events are not sent for sleeping Rigidbodies.

	function OnCollisionStay(collisionInfo : Collision) {
		// Debug-draw all contact points and normals
		for (var contact : ContactPoint in collisionInfo.contacts)
			Debug.DrawRay(contact.point, contact.normal, Color.white);
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void OnCollisionStay(Collision collisionInfo) { foreach (ContactPoint contact in collisionInfo.contacts) { Debug.DrawRay(contact.point, contact.normal, Color.white); } } }

간단히 함수에 yield statement를 사용함으로써 OnCollisionStay 는 코루틴이 될 수 있습니다.