69 lines
1.9 KiB
C#
69 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DarkTonic.MasterAudio;
|
|
using DragonLi.Core;
|
|
using DragonLi.Frame;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
using UnityEngine.XR;
|
|
|
|
//近战武器
|
|
public class MeleeWeapon : Launcher
|
|
{
|
|
public Transform[] bladePoints; // 刀刃上的关键点(顺着刀刃摆放)
|
|
public LayerMask enemyLayer;
|
|
|
|
private Vector3[] lastPositions;
|
|
|
|
public override void Start()
|
|
{
|
|
base.Start();
|
|
lastPositions = new Vector3[bladePoints.Length];
|
|
for (int i = 0; i < bladePoints.Length; i++)
|
|
lastPositions[i] = bladePoints[i].position;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (!isOwned)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// 左手
|
|
if (hand == HandType.Left)
|
|
{
|
|
transform.position = GameLocal.Ins.self.LeftHand.position;
|
|
transform.rotation = GameLocal.Ins.self.LeftHand.rotation;
|
|
}
|
|
// 右手
|
|
else if (hand == HandType.Right)
|
|
{
|
|
transform.position = GameLocal.Ins.self.RightHand.position;
|
|
transform.rotation = GameLocal.Ins.self.RightHand.rotation;
|
|
}
|
|
for (int i = 0; i < bladePoints.Length; i++)
|
|
{
|
|
Vector3 curPos = bladePoints[i].position;
|
|
|
|
// 检测轨迹是否命中敌人
|
|
if (Physics.Linecast(lastPositions[i], curPos, out RaycastHit hit, enemyLayer))
|
|
{
|
|
Vector3 effectPos = hit.point + hit.normal * 0.02f;
|
|
Quaternion effectRot = Quaternion.LookRotation(hit.normal);
|
|
muzzlePoint.position = effectPos;
|
|
muzzlePoint.rotation = effectRot;
|
|
Enemy curEnemy = hit.collider.GetComponent<Enemy>();
|
|
if (curEnemy != null)
|
|
{
|
|
curEnemy.Die(null,transform);
|
|
}
|
|
SpawnMuzzle();
|
|
}
|
|
|
|
lastPositions[i] = curPos;
|
|
}
|
|
}
|
|
|
|
}
|