79 lines
1.6 KiB
C#
79 lines
1.6 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-09-08
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "WeaponDrop" company="KUNPO"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 武器掉落
|
|||
|
/// </summary>
|
|||
|
public class WeaponDrop : MonoBehaviour
|
|||
|
{
|
|||
|
private float _maxY = 1.8f;
|
|||
|
|
|||
|
private bool _drop;
|
|||
|
|
|||
|
private Vector3 _rotateAxis;
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
_rotateAxis = transform.right;
|
|||
|
}
|
|||
|
|
|||
|
public void DropCancel()
|
|||
|
{
|
|||
|
_drop = false;
|
|||
|
CancelInvoke(nameof(Disappear));
|
|||
|
}
|
|||
|
|
|||
|
public void Drop(bool destroy)
|
|||
|
{
|
|||
|
CancelInvoke(nameof(Disappear));
|
|||
|
if (destroy)
|
|||
|
{
|
|||
|
Object.Destroy(this.gameObject, 3.5f);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Invoke(nameof(Disappear), 3.5f);
|
|||
|
}
|
|||
|
|
|||
|
_drop = true;
|
|||
|
_maxY = 1.7f;
|
|||
|
}
|
|||
|
|
|||
|
private void Disappear()
|
|||
|
{
|
|||
|
this.transform.position = Vector3.one * 4f;
|
|||
|
this.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
if (_drop)
|
|||
|
{
|
|||
|
Vector3 position = this.transform.position;
|
|||
|
if (position.y > 0.1f)
|
|||
|
{
|
|||
|
this.transform.Rotate(_rotateAxis * (position.y * 72f));
|
|||
|
_maxY -= 3.5f * Time.deltaTime;
|
|||
|
this.transform.position = position + Vector3.up * (_maxY * Time.deltaTime);
|
|||
|
return;
|
|||
|
}
|
|||
|
position.y = 0.1f;
|
|||
|
this.transform.position = position;
|
|||
|
_drop = false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|