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.
85 lines
2.8 KiB
C#
85 lines
2.8 KiB
C#
using Animancer;
|
|
using D2D;
|
|
using D2D.Utilities;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
|
|
using static D2D.Utilities.CommonGameplayFacade;
|
|
|
|
public class PistolMember : SquadMember
|
|
{
|
|
[SerializeField] private float projectileForce = 10f;
|
|
int characterIndex;
|
|
public GameObject[] charactersArray;
|
|
public Avatar[] characterAvatar;
|
|
public override void Shoot(Transform target)
|
|
{
|
|
if (reloadTime > Time.time)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var rightVector = transform.right / 2;
|
|
|
|
for (int i = 0; i < _gameData.ProjectileCount; i++)
|
|
{
|
|
var bullet = _poolHub.Spawn(_gameData.CurrentProjectilePrefab, shootPoint.transform.position);
|
|
bullet.transform.rotation = Quaternion.LookRotation(transform.forward);
|
|
|
|
var projectile = bullet.GetComponent<ProjectileComponent>();
|
|
|
|
projectile.SetColor(memberColor);
|
|
|
|
projectile.rb.velocity = Vector3.zero;
|
|
|
|
var muzzleFlash = _poolHub.Spawn(_gameData.bulletMuzzleFlash, shootPoint.transform.position);
|
|
muzzleFlash.transform.rotation = Quaternion.LookRotation(transform.forward);
|
|
|
|
var direction = (currentTarget.transform.position - shootPoint.transform.position).normalized;
|
|
|
|
Vector3 sideDir;
|
|
|
|
if ((_gameData.ProjectileCount - 1) / 2 == i)
|
|
{
|
|
sideDir = Vector3.zero;
|
|
}
|
|
else
|
|
{
|
|
sideDir = Vector3.Lerp(-rightVector, rightVector, (i + 1f) / _gameData.ProjectileCount);
|
|
|
|
}
|
|
|
|
projectile.rb.AddForce((direction + sideDir) * projectileForce, ForceMode.VelocityChange);
|
|
|
|
projectile.enterComponent.OnEnter -= HitEnemy;
|
|
projectile.enterComponent.OnEnter += HitEnemy;
|
|
}
|
|
|
|
if (lastShotSoundTime < Time.time)
|
|
{
|
|
lastShotSoundTime = Time.time + _gameData.minSoundDelay;
|
|
_audioManager.PlayOneShot(_gameData.pistolShotClip, .5f);
|
|
}
|
|
|
|
var reload = memberClass.ReloadDuration - memberClass.ReloadDuration * (1 + EvolveLevel / 20) / 1.5f;
|
|
|
|
reloadTime = Time.time + memberClass.ReloadDuration;
|
|
}
|
|
private void Start()
|
|
{
|
|
//particleController = GetComponent<ParticleController>();
|
|
characterIndex = PlayerPrefs.GetInt("currentIndex");
|
|
Debug.Log("index is" + characterIndex);
|
|
charactersArray[characterIndex].SetActive(true);
|
|
charactersArray[characterIndex].GetComponent<AnimancerComponent>().Animator.avatar = characterAvatar[characterIndex];
|
|
}
|
|
private void HitEnemy(Transform other, Transform @object)
|
|
{
|
|
if (other.CompareTag(_gameData.hittableTag))
|
|
{
|
|
other.GetComponent<IHittable>().GetHit(memberClass.Damage + EvolveLevel);
|
|
}
|
|
|
|
@object.gameObject.SetActive(false);
|
|
}
|
|
} |