miepzerino
2023-12-27 576c113fadde0791c40fad63b374f9430f875af5
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class TouchingDirections : MonoBehaviour
{
    public ContactFilter2D castFilter;
    public float groundDistance = 0.01f;
    public float wallDistance = 0.01f;
    public float ceilingDistance = 0.05f;
 
    //private Vector2 wallCheckDirection => gameObject.transform.localScale.x > 0 ? Vector2.right : Vector2.left;
 
    Rigidbody2D rb;
    public GameObject rotorGO;
 
    BoxCollider2D touchingCol;
    //CapsuleCollider2D touchingCol;
    Animator animator;
    Animator animator_rotor;
 
    public RaycastHit2D[] groundHits = new RaycastHit2D[5];
    public RaycastHit2D[] wallHitsRight = new RaycastHit2D[5];
    public RaycastHit2D[] wallHitsLeft = new RaycastHit2D[5];
    public RaycastHit2D[] ceilingHits = 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);
        }
    }
 
    [SerializeField]
    private bool _isAtWallLeft;
 
    public bool IsAtWallLeft
    {
        get { return _isAtWallLeft; }
        set
        {
            _isAtWallLeft = value;
            animator.SetBool(AnimationStrings.Player.isAtWall, value);
            animator_rotor.SetBool(AnimationStrings.Player.isAtWall, value);
        }
    }
    [SerializeField]
    private bool _isAtWallRight;
 
    public bool IsAtWallRight
    {
        get { return _isAtWallRight; }
        set
        {
            _isAtWallRight = value;
            animator.SetBool(AnimationStrings.Player.isAtWall, value);
            animator_rotor.SetBool(AnimationStrings.Player.isAtWall, value);
        }
    }
 
    [SerializeField]
    private bool _isAtCeiling;
 
    public bool IsAtCeiling
    {
        get { return _isAtCeiling; }
        set
        {
            _isAtCeiling = value;
            animator.SetBool(AnimationStrings.Player.isAtCeiling, value);
            animator_rotor.SetBool(AnimationStrings.Player.isAtCeiling, value);
        }
    }
 
    public bool IsAtWall
    {
        get
        {
            return IsAtWallLeft || IsAtWallRight;
        }
    }
 
    void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
        touchingCol = rb.GetComponent<BoxCollider2D>();
        //touchingCol = rb.GetComponent<CapsuleCollider2D>();
        animator = rb.GetComponent<Animator>();
        animator_rotor = rotorGO.GetComponent<Animator>();
    }
    // Start is called before the first frame update
    void Start()
    {
 
    }
 
    void FixedUpdate()
    {
 
        //int contactsAmount = touchingCol.GetContacts(contacts);
        //Debug.Log("contactsAmount: " + contactsAmount);
        IsGrounded = touchingCol.Cast(Vector2.down, castFilter, groundHits, groundDistance) > 0;
        IsAtWallLeft = touchingCol.Cast(Vector2.left, castFilter, wallHitsLeft, wallDistance) > 0;
        IsAtWallRight = touchingCol.Cast(Vector2.right, castFilter, wallHitsRight, wallDistance) > 0;
        IsAtCeiling = touchingCol.Cast(Vector2.up, castFilter, ceilingHits, ceilingDistance) > 0;
    }
 
    //TODO getTileForDrillHere?
}