Thought this could be useful for chopping action. Just been figuring use ability and boolions.
using UnityEngine;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities.Items;
using System.Collections;// must be included
public class Choppingaction : MonoBehaviour//
{
[Tooltip("A reference to the Ultimate Character Controller character.")]
[SerializeField] protected GameObject m_Character;
bool SwordEquipped;
/// <summary>
/// Equips the item.
/// </summary>
///
private void Update()
{
if (Input.GetKeyDown(KeyCode.J) && SwordEquipped)// or what ever key or button you like
{
var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
if (characterLocomotion != null)
{
// Equip a specific index within the ItemSetManager with the EquipUnequip ability.
var use = characterLocomotion.GetAbility<Use>();
if (use != null)
{
StartCoroutine(delay(v: 30));
}
IEnumerator delay(int v)
{
characterLocomotion.TryStartAbility(characterLocomotion.GetAbility<Use>());// 1
yield return new WaitForSeconds(0.4f);//
characterLocomotion.TryStopAbility(characterLocomotion.GetAbility<Use>());// Pause
yield return new WaitForSeconds(0.4f);//
characterLocomotion.TryStartAbility(characterLocomotion.GetAbility<Use>());// 2
yield return new WaitForSeconds(0.4f);
characterLocomotion.TryStopAbility(characterLocomotion.GetAbility<Use>());// Pause
yield return new WaitForSeconds(0.4f);//
characterLocomotion.TryStartAbility(characterLocomotion.GetAbility<Use>());// 3
yield return new WaitForSeconds(0.4f);//
characterLocomotion.TryStopAbility(characterLocomotion.GetAbility<Use>());// Pause
yield return new WaitForSeconds(0.4f);//
}
}
}
}
public void OnTriggerEnter(Collider other)// use a tag on the sword (here I have named (swordequip lower case) in unity// may be another better way to do this, I'm just learning
{
if (other.tag == "swordequip") // named the tag in lower case
{
SwordEquipped = true;// Boolion used here
}
else
{
SwordEquipped = false;
}
}
}
using UnityEngine;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities.Items;
using System.Collections;// must be included
public class Choppingaction : MonoBehaviour//
{
[Tooltip("A reference to the Ultimate Character Controller character.")]
[SerializeField] protected GameObject m_Character;
bool SwordEquipped;
/// <summary>
/// Equips the item.
/// </summary>
///
private void Update()
{
if (Input.GetKeyDown(KeyCode.J) && SwordEquipped)// or what ever key or button you like
{
var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
if (characterLocomotion != null)
{
// Equip a specific index within the ItemSetManager with the EquipUnequip ability.
var use = characterLocomotion.GetAbility<Use>();
if (use != null)
{
StartCoroutine(delay(v: 30));
}
IEnumerator delay(int v)
{
characterLocomotion.TryStartAbility(characterLocomotion.GetAbility<Use>());// 1
yield return new WaitForSeconds(0.4f);//
characterLocomotion.TryStopAbility(characterLocomotion.GetAbility<Use>());// Pause
yield return new WaitForSeconds(0.4f);//
characterLocomotion.TryStartAbility(characterLocomotion.GetAbility<Use>());// 2
yield return new WaitForSeconds(0.4f);
characterLocomotion.TryStopAbility(characterLocomotion.GetAbility<Use>());// Pause
yield return new WaitForSeconds(0.4f);//
characterLocomotion.TryStartAbility(characterLocomotion.GetAbility<Use>());// 3
yield return new WaitForSeconds(0.4f);//
characterLocomotion.TryStopAbility(characterLocomotion.GetAbility<Use>());// Pause
yield return new WaitForSeconds(0.4f);//
}
}
}
}
public void OnTriggerEnter(Collider other)// use a tag on the sword (here I have named (swordequip lower case) in unity// may be another better way to do this, I'm just learning
{
if (other.tag == "swordequip") // named the tag in lower case
{
SwordEquipped = true;// Boolion used here
}
else
{
SwordEquipped = false;
}
}
}
Last edited: