float GetRange(Vector2 dir) { float range = m_MaxRange; List <RaycastHit2D> results = new List <RaycastHit2D>(); int numHit = Physics2D.Raycast(transform.position, dir, m_ContactFilter, results); if (numHit > 0) { foreach (RaycastHit2D hit in results) { int hitLayer = hit.transform.gameObject.layer; int hitPower = (int)Mathf.Pow(2, hitLayer); if (hitPower == m_PlatformLayer) { range = hit.distance; break; } else if ((hitPower & (int)m_GunnerLayer) == (int)hitPower) { Gunner g = hit.transform.GetComponent <Gunner>(); if (g && g.Friendly == m_Friendly) { continue; } g.Damage(m_Damage, dir.normalized * m_Knockback); } } } return(range); }
protected override void OnTriggerEnter2D(Collider2D collision) { Vector2 dir = collision.transform.position - transform.position; Gunner g = collision.GetComponent <Gunner>(); if (g) { if (g.Friendly == m_Friendly) { return; } g.Damage(m_Damage, dir.normalized * m_Knockback); } }
virtual protected void OnTriggerEnter2D(Collider2D collision) { Gunner g = collision.GetComponent <Gunner>(); if (g) { if (g.Friendly != m_Friendly) { Vector2 dir = g.transform.position - transform.position; g.Damage(m_Damage, dir.normalized * m_Knockback); Kill(); } } else if (!collision.GetComponent <Bullet>()) { Kill(); } }