
1,Sword_Skill.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sword_Skill : Skill
{
// 技能信息部分
[Header("Skill info")]
// 剑的预制体,需要在 Unity 编辑器中设置
[SerializeField] private GameObject swordPrefab;
// 剑的发射力,可在 Unity 编辑器中设置
[SerializeField] private Vector2 launchForce;
// 剑受到的重力,可在 Unity 编辑器中设置
[SerializeField] private float swordGravity;
// 剑的偏移量,可在 Unity 编辑器中设置
[SerializeField] private float Py;
// 最终发射方向
private Vector2 finalDir;
// 瞄准点部分
[Header("Aim dots")]
// 瞄准点的数量,可在 Unity 编辑器中设置
[SerializeField] private int numberOFDots;
// 点与点之间的距离,可在 Unity 编辑器中设置
[SerializeField] private float spaceBeetwenDots;
// 瞄准点的预制体,需要在 Unity 编辑器中设置
[SerializeField] private GameObject dotsPrefad;
// 瞄准点的父对象,可在 Unity 编辑器中设置
[SerializeField] private Transform dotsParent;
// 存储生成的瞄准点数组
private GameObject[] dots;
// 重写 Start 方法,先调用父类的 Start 方法,再生成瞄准点
protected override void Start()
{
base.Start();
// 生成瞄准点
GenereateDots();
}
// 重写 Update 方法,处理输入和瞄准点更新
protected override void Update()
{
base.Update();
// 当鼠标右键抬起时,计算最终发射方向
if (Input.GetKeyUp(KeyCode.Mouse1))
finalDir = new Vector2(AimDirection().normalized.x * launchForce.x, AimDirection().normalized.y * launchForce.y);
// 当鼠标右键按下时,更新瞄准点位置
if (Input.GetKey(KeyCode.Mouse1))