Home > other >  Unity beginners collision problem
Unity beginners collision problem

Time:09-16

The first code is added to the collision objects, collision objects checked is the trigger, why not destroyed after collision body collision,
The second code last no work, no message and collision or add a new physical
Ask next great god, and what's the problem with the code, how to get the

CodePudding user response:

Have a great god, find video resources on the Internet, video code can run up, why to me this copy is useless,,,,

CodePudding user response:

Didn't see it very clearly what are you hang the script on the collision objects such as A and then go to the collision of the object is B I don't know what you want to destroy A or B if you want to destroy A so where are you going to judge is hit by A B was destroyed in A OnTrigger2DEnter you should have A statement to determine whether to enter A is B rather than other objects so B will use the tag of the object or the name of your first obviously didn't have the code

CodePudding user response:

B crashed A, want to destroy the B, that what code can achieve

CodePudding user response:

refer to the second floor qq_42325171 response:
see more don't know what are you hang the script on the collision objects such as A and then go to the collision of the object is B I don't know what you want to destroy A or B if you want to destroy A so where are you going to judge is hit by A B was destroyed in A OnTrigger2DEnter you should have A statement to determine whether to enter A is B rather than other objects so B will use the tag of the object or the name of your first obviously there is no this code

B crashed A, want to destroy the B, that what code can achieve

CodePudding user response:

refer to the second floor qq_42325171 response:
see more don't know what are you hang the script on the collision objects such as A and then go to the collision of the object is B I don't know what you want to destroy A or B if you want to destroy A so where are you going to judge is hit by A B was destroyed in A OnTrigger2DEnter you should have A statement to determine whether to enter A is B rather than other objects so B will use the tag of the object or the name of your first obviously there is no this code

The message after collision, and also it exerts a force, so how to achieve?

CodePudding user response:

reference 4 floor weixin_44806700 response:
Quote: refer to the second floor qq_42325171 response:
didn't see it very clearly what are you hang the script on the collision objects such as A and then go to the collision of the object is B I don't know what you want to destroy A or B if you want to destroy A so where are you going to judge is hit by A B was destroyed in A OnTrigger2DEnter you should have A statement to determine whether to enter A is B rather than other objects so B will use the tag of the object or the name of your first obviously there is no this code

B crashed A, want to destroy the B, that what code can realize
public class test: MonoBehaviour
{
//script on A, B A, destroyed B
Public GameObject B;//into B

Private void OnTriggerEnter2D (Collider2D collision)
{
If (collision. Name==B.n ame)//must know and who is this object collision of another
{
Destroy (B);
The Debug Log (collision. Name);
}
}
}

CodePudding user response:

refer to 6th floor qq_42325171 response:
Quote: refer to 4th floor weixin_44806700 response:
Quote: refer to the second floor qq_42325171 response:
see more don't know what are you hang the script on the collision objects such as A and then go to the collision of the object is B I don't know what you want to destroy A or B if you want to destroy A so where are you going to judge is hit by A B was destroyed in A OnTrigger2DEnter you should have A statement to determine whether to enter A is B rather than other objects so B will use the tag of the object or the name of your first obviously there is no this code

B crashed A, want to destroy the B, that what code can realize
public class test: MonoBehaviour
{
//script on A, B A, destroyed B
Public GameObject B;//into B

Private void OnTriggerEnter2D (Collider2D collision)
{
If (collision. Name==B.n ame)//must know and who is this object collision of another
{
Destroy (B);
The Debug Log (collision. Name);
}
}
}
if you want to destroy their destroy (gameobject)

CodePudding user response:

The second code last no work, no message and collision or add a new physical

The first point:
The last is the key: just physical strength, also did not add a physical callback is a rigid body in the news, and collision of two objects, one needs to have at least rigid body,

The second point
OnTrigger2DEnter this statement is wrong,,

//the correct format is this, the 2 d is not in the middle, but behind the most
Protected void OnTriggerEnter2D Collider2D (other) {}

CodePudding user response:

refer to the eighth floor faint a leisurely yo reply:
the second code last no work, no message and collision or add a new physical

The first point:
The last is the key: just physical strength, also did not add a physical callback is a rigid body in the news, and collision of two objects, one needs to have at least rigid body,

The second point
OnTrigger2DEnter this statement is wrong,,

//the correct format is this, the 2 d is not in the middle, but behind the most
Protected void OnTriggerEnter2D Collider2D (other) {}


//OnCollision2DEnter, of course, this also is write wrong, this is the right format
Protected void OnCollisionEnter2D Collision2D (other) {

}

CodePudding user response:

Collision detection and necessary conditions: 1, both sides have a collision body
2, the movement one party must be rigid body right

CodePudding user response:

The function name to write wrong, don't run
  • Related