You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.3 KiB
C#
88 lines
2.3 KiB
C#
using D2D;
|
|
using D2D.Utilities;
|
|
using NUnit.Framework;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using static D2D.Utilities.CommonGameplayFacade;
|
|
|
|
public class NeutralsSpawn : Unit
|
|
{
|
|
[SerializeField] private int maxNeutralsOnScreen = 8;
|
|
[SerializeField] private float spawnCooldown = .8f;
|
|
[SerializeField] private NeutralMember[] neutralMember;
|
|
//public List<GameObject> member;
|
|
private int index;
|
|
private Camera currentCamera;
|
|
|
|
private int currentAmount;
|
|
|
|
private float timer;
|
|
|
|
private void Awake()
|
|
{
|
|
|
|
currentCamera = Camera.main;
|
|
|
|
}
|
|
private void Start()
|
|
{
|
|
index = PlayerPrefs.GetInt("selectedCharacterIndex");
|
|
for (int i = 0; i < neutralMember.Length; i++)
|
|
{
|
|
neutralMember[i].gameObject.SetActive(false);
|
|
}
|
|
neutralMember[index].gameObject.SetActive(true);
|
|
Debug.Log("index" + index);
|
|
}
|
|
private void Update()
|
|
{
|
|
if (maxNeutralsOnScreen > currentAmount)
|
|
{
|
|
if (Time.time <= timer)
|
|
{
|
|
return;
|
|
}
|
|
|
|
SpawnNeutral();
|
|
|
|
timer = Time.time + spawnCooldown;
|
|
}
|
|
//neutralMember[index].gameObject.SetActive(true);
|
|
}
|
|
private void DespawnNeutral()
|
|
{
|
|
currentAmount--;
|
|
}
|
|
private void SpawnNeutral()
|
|
{
|
|
float xPos;
|
|
float yPos;
|
|
float sign = Mathf.Sign(Random.Range(-1, 2));
|
|
|
|
if (Random.Range(0, 100) > 50)
|
|
{
|
|
xPos = 0.5f + 0.6f * sign;
|
|
yPos = Random.Range(0, 100) / 100f;
|
|
}
|
|
else
|
|
{
|
|
xPos = Random.Range(0, 100) / 100f;
|
|
yPos = 0.5f + 0.6f * sign;
|
|
}
|
|
|
|
Vector3 direction = Camera.main.ViewportToWorldPoint(new Vector3(xPos, yPos, -10));
|
|
|
|
Ray ray = new Ray(currentCamera.transform.position, currentCamera.transform.position - direction);
|
|
|
|
if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, _gameData.GroundLayer))
|
|
{
|
|
NeutralMember neutralMemberComp = Instantiate(neutralMember[index].gameObject, hit.point, Quaternion.identity).Get<NeutralMember>();
|
|
neutralMemberComp.OnDespawn += DespawnNeutral;
|
|
|
|
var memberComp = neutralMemberComp.Get<SquadMember>();
|
|
memberComp.Init();
|
|
|
|
currentAmount++;
|
|
}
|
|
}
|
|
} |