Freeze Player Whilst Equipping/ Unequipping / Freeze for an event to happen

Silver100

Member
Thought this may prove useful for customising player input freeze scenario . I have been experimenting with with an idea to freeze the player whist equipping or unequipping. Basically a sleight pause each time an item is equipped/unequipped. This can be adapted how you want (It's from Opsive API script example and shared events*). Useful and much simpler than it looks. Just need to name & replace all the 'Your Character' titles in the script below with you games character and remembering to drag in the character in the inspector (public variable).
I have used this script and adapted, basically it freezes the player when equipping and unequipping suits my style of game and adjusted coroutines for delay times.

*https://opsive.com/support/documentation/ultimate-character-controller/input/
Code:
using System.Collections;
using UnityEngine;
using Opsive.Shared.Events;// Must include this
public class Freezeinput : MonoBehaviour//

{
[Tooltip("A reference to the Ultimate Character Controller character.")]
[SerializeField] public GameObject
Yourcharacter;// Simply replace 'Your character' Type in your character here.

/// <summary>
/// Disable the input.
/// </summary>

private void Start() //Sets input true
{ EventHandler.ExecuteEvent(Yourcharacter, "OnEnableGameplayInput", true);// Sets movement true.
}
void Update()// method function to //start freeze here. Pressing button
{
if (Input.GetButtonDown("Equip Next Item"))// I had string set up as y button// joystick button 3 (or however you prefer)

{

{
StartCoroutine(delay(v: 30));
EventHandler.ExecuteEvent(Yourcharacter, "OnEnableGameplayInput", true); // You could set false for immediate block or allow some time
//in my case enough time to equip time setting below can be changed to suite your freeze scenario.
}

IEnumerator delay(int v)

{
yield return new WaitForSeconds(0.4f); // Allow fraction of time say pressed 0.4 for button press
EventHandler.ExecuteEvent(Yourcharacter, "OnEnableGameplayInput", false); // Freeze
yield return new WaitForSeconds(2.00f);// Time duration until unfreeze
EventHandler.ExecuteEvent(Yourcharacter, "OnEnableGameplayInput", true); // Unfreeze
}
}
}
}
Code:
 
Last edited:
Top