62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-09-02
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "Bullet_trigger" company="Kimch"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
using UnityEngine;
|
|
|
|
namespace G
|
|
{
|
|
/// <summary>
|
|
/// 触发子弹
|
|
/// </summary>
|
|
public class Bullet_trigger : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public float bullet_speed;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Transform bullet_splash;
|
|
|
|
private Transform _splash;
|
|
private float _delayFinish;
|
|
|
|
private void Start()
|
|
{
|
|
_splash = Instantiate(bullet_splash, transform.position, Quaternion.identity);
|
|
_splash.gameObject.SetActive(false);
|
|
_splash.GetComponent<Rigidbody>().mass = this.GetComponent<Rigidbody>().mass;
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.gameObject.layer == GameLayer.UnitLayer)
|
|
{
|
|
_splash.position = this.transform.position + this.transform.forward * 0.1f;
|
|
_splash.gameObject.SetActive(true);
|
|
this.gameObject.SetActive(false);
|
|
this.transform.position = Vector3.one * 4f;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_delayFinish > 0.4f)
|
|
{
|
|
_delayFinish = 0f;
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
this.transform.Translate(Vector3.forward * (Time.deltaTime * bullet_speed));
|
|
}
|
|
}
|
|
}
|