miepzerino
2023-12-14 c91717945ccc02cdfc87d2568734d6fa9680adb7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class TouchingDirections : MonoBehaviour
{
    public ContactFilter2D castFilter;
    public float groundDistance = 0.05f;
 
    Rigidbody2D rb;
    public GameObject rotorGO;
 
    BoxCollider2D touchingCol;
    Animator animator;
    Animator animator_rotor;
 
    RaycastHit2D[] groundHits = new RaycastHit2D[5];
 
    [SerializeField]
    private bool _isGrounded;
 
    public bool IsGrounded
    {
        get { return _isGrounded; }
        set
        {
            _isGrounded = value;
            animator.SetBool(AnimationStrings.Player.IsGrounded, value);
            animator_rotor.SetBool(AnimationStrings.Player.IsGrounded, value);
        }
    }
 
 
    void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
        touchingCol = rb.GetComponent<BoxCollider2D>();
        animator = rb.GetComponent<Animator>();
        animator_rotor = rotorGO.GetComponent<Animator>();
    }
    // Start is called before the first frame update
    void Start()
    {
 
    }
 
    void FixedUpdate()
    {
        IsGrounded = touchingCol.Cast(Vector2.down, castFilter, groundHits, groundDistance) > 0;
    }
}