public void Shoot(Vector3 postion) { //Debug.Log (postion); deltaTime = 0; canShoot = false; anim.SetTrigger("isShooting"); PlayMuzzleEffect(); PlaySignEffect(); PlayShootAudio(); ShowBullet(postion); ShowShell(); //更新子弹数量显示 curMagSize -= 1; UpdateBulletDisplay(); if (shakeWhenShoot) { ShakeBackground(); } RaycastHit2D rayhit = Physics2D.Raycast(postion, Vector2.zero); bool isHitEnemy = false; if (rayhit.collider != null) { GAFEnemy gafEnemy = rayhit.collider.gameObject.GetComponentInParent <GAFEnemy>(); if (gafEnemy == null) { gafEnemy = rayhit.collider.gameObject.GetComponent <GAFEnemy>(); } if (gafEnemy != null) { // Debug.Log(gafEnemy.name); //Debug.Log(rayhit.collider.GetType()); if (rayhit.collider.GetType() == typeof(CircleCollider2D)) { gafEnemy.TakeDamage(attack, true); } else { gafEnemy.TakeDamage(attack); } isHitEnemy = true; } Shootable shootable = rayhit.collider.GetComponent <Shootable>(); if (shootable != null) { shootable.TakeDemage(attack); isHitEnemy = true; } //判断是否击中了箱子 GameItem item = rayhit.collider.GetComponent <GameItem>(); if (item) { item.TakeDamage(attack); isHitEnemy = true; } } if (!isHitEnemy) { PlaySignImpactEffect(postion); } }