void OnEnable() { if (s_Instance == null) { s_Instance = this; } else if (s_Instance != this) { throw new UnityException("There cannot be more than one BrawlerLevelHelper script. The instances are " + s_Instance.name + " and " + name + "."); } }
public void OnSceneGUI() { BrawlerLevelHelper t = target as BrawlerLevelHelper; if (!t.enabled) { return; } Vector3 start = Vector3.left * lineWidth + (Vector3.up * yOffsetProp.floatValue); Vector3 end = Vector3.right * lineWidth + (Vector3.up * yOffsetProp.floatValue); Vector3 inc = Vector3.up * layerStepSizeProp.floatValue; Handles.color = lineColor; for (int i = 0; i <= numberLayers; i++) { Handles.DrawLine(start, end); start += inc; end += inc; } }
void OnDisable() { s_Instance = null; }
void FixedUpdate() { if (!m_CanDamage) { return; } Vector2 scale = m_DamagerTransform.lossyScale; Vector2 facingOffset = Vector2.Scale(offset, scale); if (offsetBasedOnSpriteFacing && spriteRenderer != null && spriteRenderer.flipX != m_SpriteOriginallyFlipped) { facingOffset = new Vector2(-offset.x * scale.x, offset.y * scale.y); } Vector2 scaledSize = Vector2.Scale(size, scale); Vector2 pointA = (Vector2)m_DamagerTransform.position + facingOffset - scaledSize * 0.5f; Vector2 pointB = pointA + scaledSize; int hitCount = Physics2D.OverlapArea(pointA, pointB, m_AttackContactFilter, m_AttackOverlapResults); for (int i = 0; i < hitCount; i++) { m_LastHit = m_AttackOverlapResults[i]; Damageable damageable = m_LastHit.GetComponent <Damageable>(); if (damageable) { if (!useBrawlerCollision || (useBrawlerCollision && brawlerLayerWidth > Mathf.Abs(BrawlerLevelHelper.getTranslatedLayer(transform.position.y) - BrawlerLevelHelper.getTranslatedLayer(damageable.transform.position.y)))) { OnDamageableHit.Invoke(this, damageable); damageable.TakeDamage(this, ignoreInvincibility); if (disableDamageAfterHit) { DisableDamage(); } } } else { OnNonDamageableHit.Invoke(this); } } }