Advertisement
283375

SandwormAI - OnCollide

Feb 10th, 2024
1,030
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | Source Code | 0 0
  1. // SandwormAI
  2. public override void OnCollideWithPlayer(Collider other)
  3. {
  4.     base.OnCollideWithPlayer(other);
  5.     if (!isEnemyDead && emerged)
  6.     {
  7.         PlayerControllerB component = other.gameObject.GetComponent<PlayerControllerB>();
  8.         if (component != null && component.inAnimationWithEnemy == null && component == GameNetworkManager.Instance.localPlayerController)
  9.         {
  10.             EatPlayer(component);
  11.         }
  12.     }
  13. }
  14.  
  15. public void EatPlayer(PlayerControllerB playerScript)
  16. {
  17.     if (playerScript.inSpecialInteractAnimation && playerScript.currentTriggerInAnimationWith != null)
  18.     {
  19.         playerScript.currentTriggerInAnimationWith.CancelAnimationExternally();
  20.     }
  21.     playerScript.inAnimationWithEnemy = null;
  22.     playerScript.inSpecialInteractAnimation = false;
  23.     playerScript.KillPlayer(Vector3.zero, spawnBody: false);
  24. }
  25.  
  26. public override void OnCollideWithEnemy(Collider other, EnemyAI enemyScript = null)
  27. {
  28.     base.OnCollideWithEnemy(other);
  29.     if (base.IsServer && emerged)
  30.     {
  31.         enemyScript.KillEnemyOnOwnerClient(overrideDestroy: true);
  32.     }
  33. }
  34.  
  35. // EnemyAI
  36. public void KillEnemyOnOwnerClient(bool overrideDestroy = false)
  37. {
  38.     if (!enemyType.canDie || !base.IsOwner)  // <-- only killable entities
  39.     {
  40.         return;
  41.     }
  42.     // ...
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement