Support for Ultimate Character Controller and Objectives e.g. objectives found in the Unity FPS Microgame

serkai

New member
For context I started my journey in Unity with the FPS Microgame tutorial, modifying winning objectives and the flow of scenes are intuitive and scalable. For my own proof of concept I wanted more customisation for the character and weapons, which brought me to the UCC. What I need now is the best of these two frameworks to work together, or advice on the best way forward.

I attempted to import some of the objective functionality found in the FPS microgame, but I had trouble connecting objective triggers to the UCC object. Probably because my level of coding isn't good enough. If someone can advise best practises for referencing the player of UCC in a custom / FPS microgame script that would help a lot.

Alternatively help finding a guide on how to get started adding winning / losing objectives to a new project / scenes with a fresh UCC install.
 
I haven't gone through that tutorial but you'll need to ask yourself questions such as "What does it mean to win?". From there you can figure out the right hooks within the controller. As an example, with the Deathmatch AI Kit you can win by killing more than x number of enemies. In order to do this I subscribe to the OnDeath event within a new scoreboard script and increase the count. This will take some scripting but you should be able to do something similar with the FPS Microgame.
 
There is a objective to win by walking into a box collider trigger area, I'll share a snippet of the code:


Code:
using UnityEngine;

[RequireComponent(typeof(Objective), typeof(Collider))]
public class ObjectiveReachPoint : MonoBehaviour
{
    [Tooltip("Visible transform that will be destroyed once the objective is completed")]
    public Transform destroyRoot;

    Objective m_Objective;

    void Awake()
    {
        m_Objective = GetComponent<Objective>();
        DebugUtility.HandleErrorIfNullGetComponent<Objective, ObjectiveReachPoint>(m_Objective, this, gameObject);

        if (destroyRoot == null)
            destroyRoot = transform;
    }

    void OnTriggerEnter(Collider other)
    {
        if (m_Objective.isCompleted)
            return;

        var player = other.GetComponent<PlayerCharacterController>();
        // test if the other collider contains a PlayerCharacterController, then complete
        if (player != null)
        {
            m_Objective.CompleteObjective(string.Empty, string.Empty, "Objective complete : " + m_Objective.title);

            // destroy the transform, will remove the compass marker if it has one
            Destroy(destroyRoot.gameObject);
        }
    }
}

For this to import well with UCC I need to reference the component from UCC to replace the PlayerCharacterController from the FPS microgame.

I'll look at the deathmatch code in more detail to see if there is something from there that can be referenced.
 
You'd probably want to get the character's UltimateCharacterLocomotion component. However since the character's collider is probably not attached to the same transform as that component (e.g. in the demo scene it's on Nolan/Colliders/Capsule Collider), you'd need to get the UltimateCharacterLocomotion from its parents. So, you could use var locomotion = other.GetComponentInParent<UltimateCharacterLocomotion>();. (This will look for the UltimateCharacterLocomotion component in any of the collided object's parents.)
 
Top