Post by fawad on Aug 8, 2024 13:35:35 GMT
What i want to do is Control my player via animation Track As well as AI what i am currently doing is not enough
the animations works on player but position is not changing according to Track
using System;
using System.Collections;
using System.Collections.Generic;
using Invector.vCharacterController;
using UnityEngine;
public class PlayerModeManager : MonoBehaviour
{
public enum Modes
{
Default = -1,
Timeline,
Gameplay
}
[SerializeField] Modes mode;
bool hasInit = false;
private vThirdPersonInput thirdPerson;
public Modes Mode
{
get => mode;
set
{
if (mode != value)
{
mode = value;
if (hasInit)
{
SetUpMode();
}
else
{
StartCoroutine(WaitTillThenExecute(SetUpMode, () => hasInit));
}
}
}
}
private IEnumerator WaitTillThenExecute(Action setUpMode, Func<bool> condition)
{
yield return new WaitUntil(condition);
setUpMode();
}
private void SetUpMode()
{
var items = GetComponents<Behaviour>();
switch (mode)
{
case Modes.Timeline:
foreach (var item in items)
{
if (item is Animator)
{
continue;
}
else if (item is vThirdPersonController controller)
{
controller.DisableGravityAndCollision();
}
else
{
item.enabled = false;
}
}
break;
case Modes.Gameplay:
foreach (var item in items)
{
if (item is Animator)
{
continue;
}
else if (item is vThirdPersonController controller)
{
controller.EnableGravityAndCollision();
}
else
{
item.enabled = true;
}
}
//GameplayManager.Instance.PlayerManager.ResetPlayerCamera();
break;
default:
break;
}
}
private void Awake()
{
thirdPerson = GetComponent<vThirdPersonInput>();
thirdPerson.onInitComplete.AddListener(SetHasInit);
}
private void SetHasInit()
{
hasInit = true;
thirdPerson.onInitComplete.RemoveListener(SetHasInit);
}
}
the animations works on player but position is not changing according to Track