51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DragonLi.Core;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
|
|
public class Bomb : NetworkBehaviour
|
|
{
|
|
public Rigidbody rigid;
|
|
public GameObject explosion_prefab;
|
|
private bool _destroying = false;
|
|
|
|
void Start()
|
|
{
|
|
if (isServer)
|
|
{
|
|
rigid.isKinematic = false;
|
|
rigid.AddForce(transform.forward.normalized, ForceMode.Impulse);
|
|
}
|
|
else
|
|
{
|
|
rigid.isKinematic = true;
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (isServer && !_destroying)
|
|
{
|
|
if (transform.position.y <= 0)
|
|
{
|
|
_destroying = false;
|
|
rigid.isKinematic = true;
|
|
CreatExplosion();
|
|
NetworkServer.Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CreatExplosion()
|
|
{
|
|
GameObject explosion = Instantiate(explosion_prefab);
|
|
NetworkServer.Spawn(explosion);
|
|
explosion.transform.position = transform.position;
|
|
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
|
|
{
|
|
NetworkServer.Destroy(explosion);
|
|
}, 2F);
|
|
}
|
|
}
|