Good evening.
I am still very new to all this so please be gentle.
I have a character that wonders around my scene. I am attempting to use the Apex Path speed controllers / humanoid speed component to have three speed settings for each character “crawl, walk & run”. After adapting one of their examples to be GetKeyDown rather than gui buttons, I have achieved this. Alas, the script affects any selected unit, not just the unit I have the script on (important as different characters need different speed settings - so would like it to currently only affect he individual characters). I believe it’s due to these lines:
private void Awake()
{
_speedControllers = Resources.FindObjectsOfTypeAll<HumanoidSpeedComponent>();
}
I believe I need to change the “FindObjectsOfTypeAll” to just “FindMyCharacter” as it were, but have no idea what to change it to so it’s only searching to apply the Speed Controllers to the character that has the script added to it.
Full script:
(not sure I need all the “using”'s but I stuck as many as I could possibly need just to make sure for now - again, noob).
{
using System.Collections.Generic;
using System.Collections;
using Apex.Steering;
using Apex.Steering.Components;
using UnityEngine;
/// <summary>
/// A component that controls the speed of all <see cref="Apex.Steering.Components.HumanoidSpeedComponent"/> in the scene
/// </summary>
[AddComponentMenu("Apex/Examples/Omni Speed Controller", 1013)]
public class ApexUnitSpeedIncreaseIndividual : MonoBehaviour
{
private HumanoidSpeedComponent[] _speedControllers;
private void Awake()
{
_speedControllers = Resources.FindObjectsOfTypeAll<HumanoidSpeedComponent>();
}
private void Update()
{
if (Input.GetKeyDown("f1"))
foreach (var c in _speedControllers)
{
c.Crawl();
}
if (Input.GetKeyDown("f2"))
foreach (var c in _speedControllers)
{
c.Walk();
}
if (Input.GetKeyDown("f3"))
foreach (var c in _speedControllers)
{
c.Run();
}
}
}
}