{
If (Input. GetKey (KeyCode. Mouse0))
{
Destroy (gameObject);
}
}
Present situation is I click any place the object will disappear I want is only when click on the object he would disappear to do?
CodePudding user response:
The X-ray testinghttp://blog.csdn.net/weiming8517/article/details/52854220
CodePudding user response:
Physics. RaycastCodePudding user response:
Add a collision, and then register event, don't put in the updateCodePudding user response:
Your code is:If detected the left mouse button pressed, will destroy the GO,
CodePudding user response:
Using radiographic testing, hit deleteCodePudding user response:
foreach (Touch t Input in touches)//traverse Touch events
{
RaycastHit hit;//ray collision information
Ray Ray=Camera. Main. ScreenPointToRay (t.p osition);
If (t.p hase==TouchPhase. Began)//if the collision started
{
Kzflag=true;//control
If (Physics. Raycast (ray, out hit))//ray to collide
{
If (hit) the transform) gameObject. Layer==8)//touching the background layer
{
Instantiate (yanwu, hit point, hit. The transform. Rotation);//instantiate the smoke
}
If (hit) the transform) gameObject. Layer==17)//touching the metal layer
{
Instantiate (huohua, hit point, hit. The transform. Rotation);//instantiate the spark
}
If (hit) the transform) gameObject. Name=="GameStart")//start the game
{
Fyflag=2;//page marks a
//return;
}
}
If (hit) the transform) gameObject. Name=="GameStart") that is the point
CodePudding user response:
You disappear this code is to detect the mouse to clickCan consider to ray collision detection performance but consumes large
Collisions can
CodePudding user response:
Ray or collision saw others reply to tell you the basic,,,CodePudding user response:
The system has a click event interfaceCodePudding user response:
On it hang a script in the OnClick () {Destroy (TSH) GameObject)
Write to destroy} function
CodePudding user response:
I remember in the NGUI can take arbitrary objects in a script rewritten OnClick can 3 d objects that can alsoBut with ray learning words is still relatively good
And even with the OnClick around but also in its NGUI traversal or ray
So they can achieve optimum efficiency problem to suspend
CodePudding user response:
Ray:void the Update () {
//Ray radiation, the use of a camera, a method to create a Ray from the camera to the mouse to click place (not visible) if you need to see the archery, you can get a cable Renderer Line Renderer Ray objects
Ray Ray=Camera. Main. ScreenPointToRay (Input. MousePosition);
//a ray test method of physical class, created for the above ray ray ray touch point of some of the information in the hit
If (Physics. Raycast (ray, out hit)) {
//click on the Object after the judge whether the Object tag. Is it deleted.
If (hit) starts) tag=="Object" & amp; & Input. GetMouseButtonDown (0))
{
GameObject. Destroy (hit) starts) GameObject);
}
}
Put this script in the camera, or some object, but not on the deleted objects,
CodePudding user response:
Set the object tag to objectVoid the Update () {
//Ray radiation, the use of a camera, a method to create a Ray from the camera to the mouse to click place (not visible) if you need to see the archery, you can get a cable Renderer Line Renderer Ray objects
Ray Ray=Camera. Main. ScreenPointToRay (Input. MousePosition);
//a ray test method of physical class, created for the above ray ray ray touch point of some of the information in the hit
If (Physics. Raycast (ray, out hit)) {
//click on the Object after the judge whether the Object tag. Is it deleted.
If (hit) starts) tag=="Object")
{
GameObject. Destroy (hit) starts) GameObject);
}
}
CodePudding user response:
Hang the script on the object will disappear, click on the objects in the Game scene is implemented,
CodePudding user response:
Note that hit. Starts. The name is the name of the object, there's no need to set the tag.CodePudding user response:
No,!!!!!CodePudding user response:
The easiest ray detection, to use directly hit. Point, to judge by the tagCodePudding user response:
This Internet search ray detection can solveCodePudding user response:
You can try the mouse events,A flag bit in the definition, and then the mouse to enter in the object, is true, false, and leave
The click of a mouse, if it's true state, GG.
You mean the script now, click the mouse, the object disappear,,,
CodePudding user response:
Can add a script to it, write inside onm ouseDown (Destroy (this)); As is the case, can check it again, oh, to have to add a collider component to the object