glados123123123123

Untitled

Jan 13th, 2024
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. using GameNetcodeStuff;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Unity.Netcode;
  6. using UnityEngine;
  7.  
  8. namespace TombsMadnessMod.MapItems
  9. {
  10.    internal class BearTrap : NetworkBehaviour
  11.    {
  12.        private bool hasTriggered;
  13.        private Animator animator;
  14.        private AudioSource audioSource;
  15.  
  16.        public AudioClip trapCloseSFX;
  17.  
  18.        public void Start()
  19.        {
  20.            animator = GetComponent<Animator>();
  21.            audioSource = GetComponent<AudioSource>();
  22.        }
  23.        
  24.        public void OnTriggerEnter(Collider other)
  25.        {
  26.            if (hasTriggered)
  27.            {
  28.                return;
  29.            }
  30.  
  31.            if (other.CompareTag("Player"))
  32.            {
  33.                PlayerControllerB component = other.gameObject.GetComponent<PlayerControllerB>();
  34.                if (!(component != GameNetworkManager.Instance.localPlayerController) && component != null && !component.isPlayerDead)
  35.                {
  36.                   component.DamagePlayer(80, true, true, CauseOfDeath.Unknown);
  37.                   component.movementSpeed = 0.4f;
  38.                   TriggerTrapServerRpc();
  39.                }
  40.            }
  41.        }
  42.  
  43.        public void OnTriggerExit(Collider other)
  44.        {
  45.            if (other.CompareTag("Player"))
  46.            {
  47.                PlayerControllerB component = other.gameObject.GetComponent<PlayerControllerB>();
  48.                if (!(component != GameNetworkManager.Instance.localPlayerController) && component != null && !component.isPlayerDead)
  49.                {
  50.                   animator.SetBool("IsTriggerd", false);
  51.                   component.movementSpeed = 4.6f;
  52.                }
  53.            }
  54.        }
  55.  
  56.        [ServerRpc(RequireOwnership = false)]
  57.        public void TriggerTrapServerRpc(ServerRpcParams rpcParams = default)
  58.        {
  59.            foreach (var player in RoundManager.Instance.playersManager.allPlayerScripts)
  60.            {
  61.                TriggerTrapClientRpc();
  62.            }
  63.        }
  64.          
  65.        [ClientRpc]
  66.        public void TriggerTrapClientRpc(ClientRpcParams rpcParams = default)
  67.        {
  68.            audioSource.PlayOneShot(trapCloseSFX);
  69.            animator.SetBool("IsTriggerd", true);
  70.            hasTriggered = true;
  71.        }
  72.    }
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment