[API] Self-study course abroad: Related to radiographic testing

My blog  http://fasty97.top/

Self-study course abroad: This is a record of the self-study course abroad. When you are not creative, improve your ability.

This article is updated from time to time, recording some of the ray technology when doing the demo


Radiographic related

The ray detection can determine whether the specified distance is in front of the specified position and the specified direction, whether there is an object blocking, which can be used in a variety of applications, such as ray detection of bullets, sights, Npc interaction, etc.

2D rays

 if (Input.GetKeyDown(KeyCode.X))
        {
            //(射线发射位置,方向,长度)
            RaycastHit2D hit = Physics2D.Raycast(_rig.position + Vector2.up * 0.2f,
                _lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            //射线击中物体
            if (hit.collider != null)
            {
                var notice = hit.collider.GetComponent<NonPlayerCharacter>();
                if (notice != null)
                {
                    notice.DisplayDialog();
                }
            }
        }

 

Published 25 original articles · Likes6 · Visits 10,000+

Guess you like

Origin blog.csdn.net/qq_37446649/article/details/91417827