public override void MovementUpdate() { Vector2 pos = transform.position; pos.x += m_Collider.bounds.extents.x * 1.2f * m_Direction; m_Grounded = SolPhysics.DrawCast(pos, Vector2.down, 1.0f, m_GroundMask); m_HorizontalHit = SolPhysics.DrawCast(pos, transform.right * m_Direction, 3.0f, m_WallMask); if (m_Grounded) { if (!m_Bools[0]) { m_Rigidbody.velocity = new Vector2(m_Direction * m_Speed * m_Acc, m_Rigidbody.velocity.y); m_Acc = Mathf.Lerp(m_Acc, 1.0f, m_Acceleration * Time.deltaTime); } if (m_HorizontalHit) { m_Direction *= -1; Vector3 scale = transform.localScale; scale.x *= -1; transform.localScale = scale; m_Acc = 0.0f; StartCoroutine(WaitForTime(m_WaitTime, 0)); } } }
bool WallCheck() { float x = 0.0f; float dist = 0.6f; bool hit = false; for (int i = 0; i < 2; i++) { switch (i) { case 0: x = m_Collider.bounds.size.x; break; case 1: x *= -1.0f; break; } Vector2 pos = m_Collider.bounds.center; pos.x -= x / 1.9f; pos.y -= dist / 2.0f; RaycastHit2D rHit = SolPhysics.DrawCast(pos, Vector2.up, dist, m_WallMask); if (rHit) { float horizontal = Input.GetAxis("Horizontal"); switch (i) { case 0: if (horizontal < 0.0f) { m_Horizontal = 0.0f; } else if (horizontal > 0.0f) { m_Horizontal = horizontal; } break; case 1: if (horizontal > 0.0f) { m_Horizontal = 0.0f; } else if (horizontal < 0.0f) { m_Horizontal = horizontal; } break; } hit = true; } } return(hit); }
bool GroundCheck() { float dist = 0.6f; Vector2 pos = m_Collider.bounds.center; pos.y -= m_Collider.bounds.size.y / 1.9f; pos.x -= dist / 2.0f; RaycastHit2D hit = SolPhysics.DrawCast(pos, Vector2.right, dist, m_GroundMask); if (hit) { if (!m_HasLanded) { m_HasLanded = true; m_CurNumJumps = 0; m_AirTime = 0.0f; } } return(hit); }
void ShootUpdate() { float dist = Vector2.Distance(transform.position, m_PlayerTransform.position); if (dist < m_AggroRange) { Vector3 vec = (m_PlayerTransform.position - transform.position).normalized; RaycastHit2D hit = SolPhysics.DrawCast(transform.position + vec, vec, dist, m_HitScanMask); if (hit) { if (hit.transform.tag == "Player") { m_FireTimer += Time.deltaTime; if (m_FireTimer >= m_FireRate) { m_FireTimer = 0.0f; Shoot(); } } } } }