2017. 4. 3. 15:08ㆍKorean/개발백과사전
How to avoid physical collision between two object?
Here is an example.
Th first object is the tank and the second object is a bullet. Think about a tank shot cannon. but this tank and bullet have a collision object.
As soon as your tank fire the cannon, two objects are a collision and explode. This is not what you wanted to.
To Solve this problem, You have two options.
First code is like this. check object tag, and if cannon detects collision with the Tank, let's ignore it.
public class Cannon: MonoBehaviour {
private void OnCollisionEnter2D(Collision2D collision) {
if(collision.gameObject.tag == "Tank")
return;
}
}
The second way is to use physical ignore function.
Just one line of code to avoid collision between the tank and the cannon
public class Cannon: MonoBehaviour {
private void FixedUpdate() {
Physics2D.IgnoreLayerCollision(9, 10);
}
}
What is the number 9 and 10?
This is a layer number where you defined in the object.
For me, number 9 is tank named "Player", number 10 is cannon named "Weapon"
'Korean > 개발백과사전' 카테고리의 다른 글
유니티에서 다국어 앱 이름 적용하는 방법 (1) | 2017.06.13 |
---|---|
크롬에서 '다운로드폴더' 경로 변경하기 (0) | 2017.05.02 |
[VS Error] an exception has been encountered this may be caused by an extension activitylog xml (0) | 2017.03.31 |
Unity Admob CommandInvokationFailure error solution (0) | 2017.03.30 |
[Unity Fnt 폰트 적용방법] 유니티에 비트맵 폰트 적용하는 방법(NGUI가 아니라 유니티 내장 GUI입니다.) (0) | 2017.03.17 |