unity3d-Ray (Ray)

Source: Internet
Author: User

Beam Ray Ray

A ray is a line that occurs at a point to another point that, once collided with another model, will stop firing. Note that this condition is logical and not visible on the interface.

Generally use the ray to determine whether to launch to a game object or to get a mouse click on the game object and so on.

Use Camera.main.ScreenPointToRay to send a ray to the screen.

1     Ray Ray = Camera.main.ScreenPointToRay (input.mouseposition); 2     Raycasthit hit; 3    if (Physics.raycast (Ray, out hits)// if hit 4     {5      // Hit.collider.gameObject can get the hit game object 6     }

The difference between Raycast and Raycastall

Raycast: Once collided with other models, he will stop firing.

Raycastall: Casts a ray and returns all collisions

Let's do a little case demonstration. The difference between this two. I simulate the left and right mouse clicks and emit rays separately,

1:raycast colliding objects. Set to Blue

1:raycastall all objects that collide. Set to Red

I can see it from here. When you right-click. The rays passed through two cubes, all turned red. You can see the effect in the scene, and the left-click Turns blue.

1 voidUpdate ()2     {3 4         if(Input.getmousebuttondown (0))//Click the left mouse button5         {6             //Case One: Demo Raycast,7Ray Ray =Camera.main.ScreenPointToRay (input.mouseposition);8 Raycasthit hit;9             if(Physics.raycast (Ray, outHit))//if hit, change to blue colorTen             { OneHit.transform.renderer.material.color =Color.Blue; A                 //hit.collider.gameObject.transform.renderer.material.color = color.red; -             } -  the  -         } -  -         if(Input.getmousebuttondown (1))//Click the right mouse button +         { -Ray Ray =Camera.main.ScreenPointToRay (input.mouseposition); +             //Case Two: demo Raycastall Araycasthit[] Hi =Physics.raycastall (Ray); at             if(Hi. Length >0) -             { -                  for(inti =0; I < hi. Length; i++)//change the red color of all hit objects -                 { -Hi[i].collider.transform.renderer.material.color =color.red; -                 } in             } -         } to}

Sky Box (skyboxes)

The game scene has not found that the sky is clear sunny day, look at the mood are much more comfortable. This is the package that unity comes with and operates as follows:

1: Guide Pack

2: You can see it in the Resources folder after the import is complete

3: Set How the sky is rendered in the scene

Both options can be set: Drag directly or open the window selection.

unity3d-Ray (Ray)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.