| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- public class StoneStatue:MonoBehaviour
- {
- public GameObject bulletPrefab;
- public GameObject parent;
- private AttackController ac;
- [Header("子弹发射设置,子弹参数在AttackControlller的行军式中设置")]
- [LabelText("子弹数量")] public int bulletCount = 3;
- [LabelText("基础速度")] public float baseSpeed = 10f;
- [LabelText("速度随机范围")] public float speedRandomRange = 2f;
- [LabelText("角度随机范围")] public float angleRandomRange = 5f;
- [LabelText("子弹伤害与击破者伤害的比率")] public float damageRate = 1;
- [Header("向左发射角度")]
- [LabelText("向左发射的基础角度")] public float leftBaseAngle = 135f;
- [LabelText("向左发射的角度范围")] public float leftAngleRange = 60f;
-
- [Header("向右发射角度")]
- [LabelText("向右发射的基础角度")] public float rightBaseAngle = 45f;
- [LabelText("向右发射的角度范围")] public float rightAngleRange = 60f;
- public GameObject disappearEffect;
- private void Awake()
- {
- ac = GetComponent<AttackController>();
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.layer == 20)
- {
- AttackTrigger attackTrigger = other.gameObject.GetComponent<AttackTrigger>();
- if(attackTrigger != null)
- {
- AttackController.AttackMethod attackMethod = other.gameObject.GetComponent<AttackTrigger>().attackMethod;
- AttackInfo attackInfo = attackMethod.attackInfo;
- Character attackFrom = attackTrigger.owner;
- if ((attackFrom.CompareTag("Demonic") || attackFrom.CompareTag("Player")) && attackInfo.attackMethod_Type == AttackMethod_Type.Attack_Summon)
- {
- foreach (AttackEffect attackEffect in attackInfo.attackEffect)
- {
- if (attackEffect == AttackEffect.BlowUp)
- {
- Vector3 vec3 = attackMethod.attackInfo.blowUp.dir;
- int attackDir = 0;
- switch (attackMethod.attackInfo.blowUp.directionType)
- {
- case AttackInfo.BlowUp.DirectionType.Common:
- attackDir = attackFrom.bodyTrans.localScale.x < 0 ? -1 : 1;
- break;
- case AttackInfo.BlowUp.DirectionType.Spread:
- attackDir = attackFrom.transform.position.x < transform.position.x ? -1 : 1;
- break;
- }
- if (attackDir < 0)
- {
- vec3.x = -vec3.x;
- }
- if (GameManager.instance.isWoodRockEnable)
- {
- int randomInt = Random.Range(0, 100);
- if (randomInt < GameManager.instance.woodRockProbability && GameManager.instance.player.deadDemonicList.Count > 0)
- {
- randomInt = Random.Range(0, GameManager.instance.player.deadDemonicList.Count);
- DeadDemonicInformation deadDemonicInformation = GameManager.instance.player.deadDemonicList[randomInt];
- Demonic demonic = GameManager.instance.player.CreateDemonic(deadDemonicInformation.id);
- demonic.attackController.attackSummonId = 0;
- demonic.Attack_summon();
- GameManager.instance.player.deadDemonicList.Remove(deadDemonicInformation);
- PoolManager.Instantiate(Resources.Load<GameObject>("Prefab/SoulFlower"), demonic.transform.position + Vector3.up * 2, Quaternion.identity, demonic.transform).GetComponent<SoulFlower>().Init(true);
- }
- }
- Shoot(vec3, attackFrom);
- }
- }
- }
- }
-
- }
- }
- private void Shoot(Vector3 attackDir,Character attackFrom)
- {
- if (bulletPrefab == null)
- {
- Debug.LogError("bulletPrefab未设置!");
- return;
- }
- // 判断攻击方向(向左还是向右)
- bool isAttackingRight = attackDir.x > 0;
- // 根据方向选择发射角度范围
- float baseAngle = isAttackingRight ? rightBaseAngle : leftBaseAngle;
- float angleRange = isAttackingRight ? rightAngleRange : leftAngleRange;
- // 计算角度步长(均匀分布)
- float angleStep = angleRange / (bulletCount - 1);
- float startAngle = baseAngle - angleRange / 2f;
- for (int i = 0; i < bulletCount; i++)
- {
- // 计算基础角度(均匀分布)
- float currentAngle = startAngle + angleStep * i;
- // 添加随机角度偏移
- float randomAngleOffset = Random.Range(-angleRandomRange, angleRandomRange);
- float finalAngle = currentAngle + randomAngleOffset;
- // 计算方向向量
- float rad = finalAngle * Mathf.Deg2Rad;
- Vector3 bulletDirection = new Vector3(Mathf.Cos(rad), Mathf.Sin(rad), 0f);
- // 计算随机速度
- float randomSpeed = baseSpeed + Random.Range(-speedRandomRange, speedRandomRange);
- Vector3 bulletVelocity = bulletDirection * randomSpeed;
- // 创建子弹
- CreateBullet(bulletDirection, bulletVelocity, attackFrom);
- parent.SetActive(false);
- }
- }
- private void CreateBullet(Vector3 direction, Vector3 velocity,Character attackFrom)
- {
- GameObject bulletObj = PoolManager.Instantiate(bulletPrefab, transform.position + Vector3.up * 2, Quaternion.identity);
- // 设置子弹朝向
- bulletObj.transform.right = direction;
- // 获取子弹组件并设置属性
- Bullet bullet = bulletObj.GetComponent<Bullet>();
- if (bullet != null)
- {
- ac.attackMethod_march[0].attackInfo.damage = (int)(attackFrom.attackController.attackMethod_summon[0].attackInfo.damage * damageRate);
- bullet.BeShoot(attackFrom, transform.position, direction,false,false,null, ac.attackMethod_march[0]);
- }
- //Debug.Log($"发射子弹,方向:{direction},速度:{velocity.magnitude}");
- }
- private void OnDisable()
- {
- if(disappearEffect != null) PoolManager.Instantiate(disappearEffect, transform.position, new Quaternion(0, 0, 0, 0));
- GameManager.instance.player.rebornSkills.Remove(this);
- }
- }
|