| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MultiShot : MonoBehaviour
- {
- [Header("主银")]
- public Character owner;
- [Header("弓箭预制体")]
- public GameObject arrow;
- [Header("齐发参数")]
- public int num;
- public float angle;
- public float arrivalAngle;
- public int damage;
- public bool tryy;
- public float gravity = 9.8f; // 重力加速度
- public float speed;
- public void Shoot()
- {
- float angleInterval = num > 1 ? angle / (float)(num - 1) : 0f;
- for (int i = 0; i < num; i++)
- {
- float ang = 0;
- GameObject obj = Instantiate(arrow);
- MultiArrowController arrowController = obj.AddComponent<MultiArrowController>();
- Vector3 dir = Vector3.zero;
- if (owner.bodyTrans.localScale.x > 0)
- {
- ang = 180 - arrivalAngle - angle / 2 + i * angleInterval;
- }
- else
- {
- ang = arrivalAngle - angle / 2 + i * angleInterval;
- }
- ang = ang / 180 * Mathf.PI;
- dir = new Vector3(Mathf.Cos(ang), Mathf.Sin(ang), 0);
- obj.GetComponent<Bullet>().BeShoot(owner, owner.transform.position + Vector3.up, dir, damage, 0, false, 0);
- arrowController.Initialize(gravity, speed);
- }
- }
- private void Update()
- {
- if (tryy)
- {
- tryy = false;
- Shoot();
- }
- }
- }
|