Beispiel #1
0
        public override void OnAwake()
        {
            _SP_NPC = gameObject.AddComponent <SP_NPC>();

            _SP_NPC.PlayerHeight = PlayerHeight.Value;
            _SP_NPC.Hand         = Hand.Value;

            Animator animator = GetComponent <Animator>();

#if UNITY_EDITOR
            _SP_NPC.ResetAnimator = ResetAnimator.Value;

            if (ResetAnimator.Value)
            {
                if (animator)
                {
                    Debug.LogError("No debe haber un Animator asociado al NPC");
                }

                else
                {
                    //https://docs.unity3d.com/ScriptReference/Animations.AnimatorController.html?_ga=2.239912643.1726044905.1583340668-154422748.1555576536
                    animator = gameObject.AddComponent <Animator>();

                    string animatorControllerPath = "Assets/SP_NPC_Controller.controller";

                    //Destruye el asset del animator controller
                    AssetDatabase.DeleteAsset(animatorControllerPath);

                    // Creates the controller
                    AnimatorController animatorController = AnimatorController.CreateAnimatorControllerAtPath(animatorControllerPath);
                    animator.runtimeAnimatorController = animatorController;

                    //Creación del estado inicial
                    var rootStateMachine = animatorController.layers[0].stateMachine;
                    var newState         = rootStateMachine.AddState("Entry State");

                    _SP_NPC.AnimatorController = animatorController;
                }
            }
            else
            {
                if (!animator)
                {
                    Debug.LogError("Debe haber un Animator asociado al NPC");
                }
            }
#endif
        }
 /// <summary>
 /// Obtiene referencias
 /// </summary>
 public override void OnAwake()
 {
     NPC = GetComponent <SP_NPC>();
 }
        private bool success;       // Booleana que indica si puede recoger el objeto correctamente

        /// <summary>
        /// Obtiene referencias
        /// </summary>
        public override void OnAwake()
        {
            NPC  = GetComponent <SP_NPC>();
            hand = NPC.Hand;
        }