discofever
New member
First off apologies for my "n00bness" in understanding how UCC works.
So i want to make a simple interaction; character comes and picks up a bottle.
I've added a "Screen Interact" ability in the Abilites and "Move towards".
Character walks to the object but then nothing happens. Using FinalIK.
Here is my setup :
On the object
and
So i want to make a simple interaction; character comes and picks up a bottle.
I've added a "Screen Interact" ability in the Abilites and "Move towards".
Character walks to the object but then nothing happens. Using FinalIK.
Here is my setup :
On the object
C#:
using UnityEngine;
using Opsive.UltimateCharacterController.Traits;
// using UnityEngine.Events;
public class PickInteractable : MonoBehaviour, IInteractableTarget
{
// bool hasInteracted = false;
// public UnityEvent onInteract;
public bool CanInteract(GameObject character)
{
return true;
}
public void Interact(GameObject character)
{
Debug.Log("Interact!");
// hasInteracted = true;
// onInteract?.Invoke();
}
}
and
C#:
using Opsive.UltimateCharacterController.Character.Abilities;
using UnityEngine;
[DefaultStartType(AbilityStartType.ButtonDown)]
[DefaultInputName("Action")]
[DefaultAbilityIndex(9)]
[DefaultAllowPositionalInput(false)]
[DefaultAllowRotationalInput(false)]
[AllowMultipleAbilityTypes]
public class ScreenInteract : Interact
{
public override bool CanStartAbility()
{
if (DetectUsingRaycast())
{
return base.CanStartAbility();
}
return false;
}
protected override void AbilityStarted()
{
Debug.Log("ScreenInteract Started");
base.AbilityStarted();
}
protected override void AbilityStopped(bool force)
{
Debug.Log("ScreenInteract Stopped");
base.AbilityStopped(force);
}
private bool DetectUsingRaycast()
{
if (m_LookSource == null)
{
return false;
}
if (Physics.Raycast(m_LookSource.Transform.position, m_LookSource.Transform.forward, out m_RaycastResult, m_CastDistance, m_DetectLayers, QueryTriggerInteraction.Collide))
{
Debug.DrawRay(m_LookSource.Transform.position, m_LookSource.Transform.forward, Color.green);
var hitObject = m_RaycastResult.collider.gameObject;
if (ValidateObject(hitObject, false))
{
m_DetectedObject = hitObject;
return true;
}
}
return false;
}
}