I found this API very useful (and made some changes) where I was struggling to find a way to make my player change equip status and after time duration too this is a great solution, could be useful;
I have placed the Unequip/Unequip code into coroutine. (Found in Opsive documents API Equip / Unequip)
When item is picked up, it automatically equips. After time the item will automatically unequip. (I have this in my game where weapons are available over a specific time as opposed to ammo)
API; Equip Unequip
Equip Unequip API Variation with Co-routine;
using UnityEngine;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities.Items;
using System.Collections;// Must be included for using coroutines
public class MyAIAgent : MonoBehaviour
{
[Tooltip("A reference to the Ultimate Character Controller character.")] // Drag your character in the inspector to work//
[SerializeField] protected GameObject m_Character;
/// <summary>
/// Equips the item.
/// </summary>
///
public void OnTriggerEnter(Collider other)//
{//
if (other.tag == "mgpickup") //
{
var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
if (characterLocomotion != null)
{
// Equip a specific index within the ItemSetManager with the EquipUnequip ability.
var equipUnequip = characterLocomotion.GetAbility<EquipUnequip>();
if (equipUnequip != null)
{
equipUnequip.StartEquipUnequip(1); // Rifle equipped on pick up
StartCoroutine(delay(v: 30));
}
IEnumerator delay(int v)
{
yield return new WaitForSeconds(0.5f);
// Equip the ItemSet at index 2 within the ItemSetManager.
equipUnequip.StartEquipUnequip(1);
yield return new WaitForSeconds(18.8f);// Time to wait
equipUnequip.StartEquipUnequip(-1); switching to unequip
//(-1)= Unequip/ (1)= Rifle equip (2)= Sword equip
}
}
}
}
}
I have placed the Unequip/Unequip code into coroutine. (Found in Opsive documents API Equip / Unequip)
When item is picked up, it automatically equips. After time the item will automatically unequip. (I have this in my game where weapons are available over a specific time as opposed to ammo)
API; Equip Unequip
Equip Unequip API Variation with Co-routine;
Code:
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities.Items;
using System.Collections;// Must be included for using coroutines
public class MyAIAgent : MonoBehaviour
{
[Tooltip("A reference to the Ultimate Character Controller character.")] // Drag your character in the inspector to work//
[SerializeField] protected GameObject m_Character;
/// <summary>
/// Equips the item.
/// </summary>
///
public void OnTriggerEnter(Collider other)//
{//
if (other.tag == "mgpickup") //
{
var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
if (characterLocomotion != null)
{
// Equip a specific index within the ItemSetManager with the EquipUnequip ability.
var equipUnequip = characterLocomotion.GetAbility<EquipUnequip>();
if (equipUnequip != null)
{
equipUnequip.StartEquipUnequip(1); // Rifle equipped on pick up
StartCoroutine(delay(v: 30));
}
IEnumerator delay(int v)
{
yield return new WaitForSeconds(0.5f);
// Equip the ItemSet at index 2 within the ItemSetManager.
equipUnequip.StartEquipUnequip(1);
yield return new WaitForSeconds(18.8f);// Time to wait
equipUnequip.StartEquipUnequip(-1); switching to unequip
//(-1)= Unequip/ (1)= Rifle equip (2)= Sword equip
}
}
}
}
}
Code:
Last edited: