From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/WallRayCaster.cs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 GameCode/WallRayCaster.cs (limited to 'GameCode/WallRayCaster.cs') 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(); + data = GetComponent(); + rig = GetComponent(); + } + + 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() && Vector3.Angle(raycastHit2D.normal, Vector3.up) > 70f && Vector3.Angle(raycastHit2D.normal, Vector3.up) < 110f) + { + data.TouchWall(raycastHit2D.normal, raycastHit2D.point); + } + } +} -- cgit v1.1-26-g67d0