FANDOM


A character's "Motion control" property determines whether AC will move the character automatically or not. When set to Manual, the character is assumed to be moved by something other than the NPC or Player component, i.e. a third-party motion controller script.

This Action lets you dynamically change this property in ActionLists, so that you can have the character rely on AC for motion control at some times, and another way of moving them for others.

ActionMotionControl.cs:

using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace AC
{

[System.Serializable]
public class ActionMotionControl : Action
{

public bool isPlayer;
public Char character;
public int characterConstantID = 0;
public MotionControl motionControl;
private Char runtimeCharacter;


public ActionMotionControl ()
{
this.isDisplayed = true;
category = ActionCategory.Character;
title = "Set motion control";
description = "This is a blank Action template.";
}


public override void AssignValues (List<ActionParameter> parameters)
{
runtimeCharacter = (isPlayer) ? KickStarter.player : AssignFile <Char> (characterConstantID, character);
}


public override float Run ()
{
if (runtimeCharacter)
{
runtimeCharacter.motionControl = motionControl;
}
return 0f;
}


#if UNITY_EDITOR

public override void ShowGUI ()
{
isPlayer = EditorGUILayout.Toggle ("Affect Player?", isPlayer);
if (!isPlayer)
{
character = (Char) EditorGUILayout.ObjectField ("Character to affect:", character, typeof (Char), true);

characterConstantID = FieldToID <Char> (character, characterConstantID);
character = IDToField <Char> (character, characterConstantID, false);
}

motionControl = (MotionControl) EditorGUILayout.EnumPopup ("New motion control:", motionControl);

AfterRunningOption ();
}

#endif

}

}
Community content is available under CC-BY-SA unless otherwise noted.