Exemplo n.º 1
0
    protected virtual void OnTriggerEnter2D(Collider2D other)
    {
//        Debug.Log(name + " trigger:" + other.name);
        Mover mover = other.GetComponent <Mover>();

        if (mover != null)
        {
            mover.ChangeHealth(-hitDamage);
        }
    }
Exemplo n.º 2
0
    // 对激光范围内所有敌方施加伤害
    private void RayCast(float length)
    {
        ray.transform.localScale = new Vector3(rayWidth, length, 1);
        var hits = Physics2D.BoxCastAll(gunPoint.position, new Vector2(rayWidth, 0.1f), 0, transform.up, length,
                                        GetAgainstLayerMask(gameObject.layer));

        for (int i = 0; i < hits.Length; i++)
        {
            Mover mover = hits[i].collider.GetComponent <Mover>();
            if (mover != null)
            {
                if (mover is Plane)
                {
                    // 如果是Plane 则要有爆炸效果
                    GameObject explosion = PoolManager.Instance.GetInstance(rayHitExplosionPrefab.name);
                    explosion.transform.localScale = new Vector3(rayWidth, rayWidth, 1);
                    explosion.transform.position   = hits[i].point;
                }

                mover.ChangeHealth(-damage);
            }
        }
    }