Skip to main content

Use of Raycast to determine certain game objects ?

Raycast can be use in many fire like : There are many raycast type but these two are most that i used. 1.Physics.Raycast               Player shooting/Fire 2.Physics.SphereCast         Detect A object to Apply force due to explosion effect. Simple Physics Raycast as shown below :    RaycastHit hit;   Ray ray;    void Update ()     {         if ( Input .GetMouseButton(0))         {             ray = Camera .main.ScreenPointToRay( Input. mousePosition);               if ( Physics .Raycast(ray, out hit))             {                 Debug .Log( "Ray cast hit too " + hit.collider.gameObject.name);             }         }  }

Use of Raycast to determine certain game objects ?

Raycast can be use in many fire like :

There are many raycast type but these two are most that i used.

1.Physics.Raycast    

      Player shooting/Fire

2.Physics.SphereCast 

      Detect A object to Apply force due to explosion effect.

Simple Physics Raycast as shown below :

  RaycastHit hit;

  Ray ray;

  void Update()

    {

        if(Input.GetMouseButton(0))

        {

            ray = Camera.main.ScreenPointToRay(Input.mousePosition);

             if (Physics.Raycast(ray, out hit))

            {

                Debug.Log("Ray cast hit too " + hit.collider.gameObject.name);

            }

        }

 }

Comments