diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/WallRayCaster.cs |
+ init
Diffstat (limited to 'GameCode/WallRayCaster.cs')
-rw-r--r-- | GameCode/WallRayCaster.cs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/GameCode/WallRayCaster.cs b/GameCode/WallRayCaster.cs new file mode 100644 index 0000000..b7d5c52 --- /dev/null +++ b/GameCode/WallRayCaster.cs @@ -0,0 +1,34 @@ +using UnityEngine; + +public class WallRayCaster : MonoBehaviour +{ + public float rayLength = 0.7f; + + public LayerMask mask; + + private GeneralInput input; + + private CharacterData data; + + private Rigidbody2D rig; + + private void Start() + { + input = GetComponent<GeneralInput>(); + data = GetComponent<CharacterData>(); + rig = GetComponent<Rigidbody2D>(); + } + + private void Update() + { + } + + public void RayCast(Vector3 dir, float offset = 0f) + { + RaycastHit2D raycastHit2D = Physics2D.Raycast(base.transform.position + base.transform.up * offset, dir, rayLength * base.transform.localScale.x, mask); + if ((bool)raycastHit2D.transform && !raycastHit2D.collider.GetComponent<DamageBox>() && Vector3.Angle(raycastHit2D.normal, Vector3.up) > 70f && Vector3.Angle(raycastHit2D.normal, Vector3.up) < 110f) + { + data.TouchWall(raycastHit2D.normal, raycastHit2D.point); + } + } +} |