93 lines
2.9 KiB
C#
93 lines
2.9 KiB
C#
using System.Net;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DarkTonic.MasterAudio;
|
|
using DG.Tweening;
|
|
using DragonLi.Core;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
using Valheim;
|
|
|
|
public class SpwanBallPoint : NetworkBehaviour
|
|
{
|
|
// Start is called before the first frame update
|
|
public GameObject ballPre;
|
|
|
|
public List<Rigidbody> rigidbodys;
|
|
|
|
[SoundGroup] public string flySound;
|
|
|
|
private bool _IsEnd = false;
|
|
private List<bool> _IsNearbys = new List<bool>();
|
|
private List<bool> _IsDestorys = new List<bool>();
|
|
|
|
public void Start()
|
|
{
|
|
if (isServer)
|
|
{
|
|
StartCoroutine(SpawnBalls());
|
|
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
|
|
{
|
|
NetworkServer.Destroy(transform.gameObject);
|
|
}, 12F);
|
|
}
|
|
}
|
|
|
|
IEnumerator SpawnBalls()
|
|
{
|
|
for (int i = 0; i < MRNetworkManager.Ins.roomSlots.Count * 5; i++)
|
|
{
|
|
GameObject ball = GameManager.Ins.CreateEnergyBall(transform.position);
|
|
float randomX = Random.Range(-10f, 10f);
|
|
float randomY = Random.Range(-10f, 10f);
|
|
Rigidbody rigidbody = ball.GetComponent<Rigidbody>();
|
|
rigidbodys.Add(rigidbody);
|
|
rigidbody.AddForce(new Vector3(randomX, 22F, randomY), ForceMode.Impulse);
|
|
_IsNearbys.Add(false);
|
|
_IsDestorys.Add(false);
|
|
yield return new WaitForSeconds(0.15F);
|
|
}
|
|
yield return new WaitForSeconds(1F);
|
|
_IsEnd = true;
|
|
StopCoroutine(SpawnBalls());
|
|
}
|
|
|
|
|
|
public void Update()
|
|
{
|
|
if (isServer)
|
|
{
|
|
for (int i = 0; i < rigidbodys.Count; i++)
|
|
{
|
|
if (rigidbodys[i] && rigidbodys[i].transform.position.y <= 0.06)
|
|
{
|
|
rigidbodys[i].useGravity = false;
|
|
rigidbodys[i].velocity = Vector3.zero;
|
|
|
|
}
|
|
if (_IsEnd && rigidbodys[i])
|
|
{
|
|
int playerIndex = i / 5;
|
|
Vector3 newPos = MRNetworkManager.Ins.roomSlots[playerIndex].transform.position;
|
|
newPos.y = 0.8f;
|
|
rigidbodys[i].transform.position = Vector3.MoveTowards(rigidbodys[i].transform.position, newPos, 4f * Time.deltaTime);
|
|
|
|
if (!_IsNearbys[i] && Vector3.Distance(rigidbodys[i].transform.position, newPos) < 1F)
|
|
{
|
|
_IsNearbys[i] = true;
|
|
MasterAudio.PlaySound3DFollowTransform(flySound, rigidbodys[i].transform);
|
|
}
|
|
if (!_IsDestorys[i] && Vector3.Distance(rigidbodys[i].transform.position, newPos) < 0.3f)
|
|
{
|
|
_IsDestorys[i] = true;
|
|
NetworkServer.Destroy(rigidbodys[i].gameObject);
|
|
rigidbodys[i] = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|