80 lines
2 KiB
C#
80 lines
2 KiB
C#
using GameNetcodeStuff;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
|
|
public class EnemyAICollisionDetect : MonoBehaviour, IHittable, INoiseListener, IShockableWithGun
|
|
{
|
|
public EnemyAI mainScript;
|
|
|
|
public bool canCollideWithEnemies;
|
|
|
|
private void OnTriggerStay(Collider other)
|
|
{
|
|
if (other.CompareTag("Player"))
|
|
{
|
|
mainScript.OnCollideWithPlayer(other);
|
|
}
|
|
else if (canCollideWithEnemies && other.CompareTag("Enemy"))
|
|
{
|
|
EnemyAICollisionDetect component = other.gameObject.GetComponent<EnemyAICollisionDetect>();
|
|
if (component != null && component.mainScript != mainScript)
|
|
{
|
|
mainScript.OnCollideWithEnemy(other, component.mainScript);
|
|
}
|
|
}
|
|
}
|
|
|
|
void IHittable.Hit(int force, Vector3 hitDirection, PlayerControllerB playerWhoHit, bool playHitSFX)
|
|
{
|
|
mainScript.HitEnemyOnLocalClient(force, hitDirection, playerWhoHit, playHitSFX);
|
|
}
|
|
|
|
void INoiseListener.DetectNoise(Vector3 noisePosition, float noiseLoudness, int timesNoisePlayedInOneSpot, int noiseID)
|
|
{
|
|
mainScript.DetectNoise(noisePosition, noiseLoudness, timesNoisePlayedInOneSpot, noiseID);
|
|
}
|
|
|
|
bool IShockableWithGun.CanBeShocked()
|
|
{
|
|
if (mainScript.postStunInvincibilityTimer <= 0f && mainScript.enemyType.canBeStunned)
|
|
{
|
|
return !mainScript.isEnemyDead;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
Vector3 IShockableWithGun.GetShockablePosition()
|
|
{
|
|
if (mainScript.eye != null)
|
|
{
|
|
return mainScript.eye.position;
|
|
}
|
|
return base.transform.position + Vector3.up * 0.5f;
|
|
}
|
|
|
|
float IShockableWithGun.GetDifficultyMultiplier()
|
|
{
|
|
return mainScript.enemyType.stunGameDifficultyMultiplier;
|
|
}
|
|
|
|
void IShockableWithGun.ShockWithGun(PlayerControllerB shockedByPlayer)
|
|
{
|
|
mainScript.SetEnemyStunned(setToStunned: true, 0.25f, shockedByPlayer);
|
|
mainScript.stunnedIndefinitely++;
|
|
}
|
|
|
|
Transform IShockableWithGun.GetShockableTransform()
|
|
{
|
|
return base.transform;
|
|
}
|
|
|
|
NetworkObject IShockableWithGun.GetNetworkObject()
|
|
{
|
|
return mainScript.NetworkObject;
|
|
}
|
|
|
|
void IShockableWithGun.StopShockingWithGun()
|
|
{
|
|
mainScript.stunnedIndefinitely = Mathf.Clamp(mainScript.stunnedIndefinitely - 1, 0, 100);
|
|
}
|
|
}
|