Example #1
0
        private void Start()
        {
            //Get other RPG Character components.
            superCharacterController    = GetComponent <SuperCharacterController>();
            rpgCharacterController      = GetComponent <RPGCharacterControllerFREE>();
            rpgCharacterInputController = GetComponent <RPGCharacterInputControllerFREE>();
            navMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent>();

            //Check if Animator exists, otherwise pause script.
            animator = GetComponentInChildren <Animator>();
            if (animator == null)
            {
                Destroy(this);
                return;
            }

            //Setup Collider and Rigidbody for collisions.
            capCollider = GetComponent <CapsuleCollider>();
            rb          = GetComponent <Rigidbody>();
            if (rb != null)
            {
                //Set restraints on startup if using Rigidbody.
                rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
            }

            SwitchCollisionOn();

            //Set currentState to idle on startup.
            currentState      = RPGCharacterState.Idle;
            rpgCharacterState = RPGCharacterState.Idle;
        }
 private void Awake()
 {
     rpgCharacterMovementController = GetComponent <RPGCharacterMovementControllerFREE>();
     rpgCharacterWeaponController   = GetComponent <RPGCharacterWeaponControllerFREE>();
     rpgCharacterInputController    = GetComponent <RPGCharacterInputControllerFREE>();
     //Setup Animator, add AnimationEvents script.
     animator = GetComponentInChildren <Animator>();
     if (animator == null)
     {
         Debug.LogError("ERROR: There is no Animator component for character.");
         Destroy(this);
     }
     else
     {
         animator.gameObject.AddComponent <RPGCharacterAnimatorEventsFREE>();
         animator.GetComponent <RPGCharacterAnimatorEventsFREE>().rpgCharacterController = this;
         animator.gameObject.AddComponent <AnimatorParentMoveFREE>();
         animator.GetComponent <AnimatorParentMoveFREE>().anim = animator;
         animator.GetComponent <AnimatorParentMoveFREE>().rpgCharacterMovementController = rpgCharacterMovementController;
     }
     ikHands = GetComponent <IKHandsFREE>();
     //Set for starting Unarmed state.
     weapon = Weapon.UNARMED;
     animator.SetInteger("Weapon", 0);
     animator.SetInteger("WeaponSwitch", -1);
     StartCoroutine(_ResetIdleTimer());
 }
 private void Awake()
 {
     superCharacterController    = GetComponent <SuperCharacterController>();
     rpgCharacterController      = GetComponent <RPGCharacterControllerFREE>();
     rpgCharacterInputController = GetComponent <RPGCharacterInputControllerFREE>();
     navMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent>();
     animator     = GetComponentInChildren <Animator>();
     capCollider  = GetComponent <CapsuleCollider>();
     rb           = GetComponent <Rigidbody>();
     if (rb != null)
     {
         //Set restraints on startup if using Rigidbody.
         rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
     }
     //Set currentState to idle on startup.
     currentState      = RPGCharacterState.Idle;
     rpgCharacterState = RPGCharacterState.Idle;
 }
Example #4
0
        private void Awake()
        {
            //Initialize other RPG scripts.
            rpgCharacterMovementControllerFREE = GetComponent <RPGCharacterMovementControllerFREE>();
            rpgCharacterWeaponControllerFREE   = GetComponent <RPGCharacterWeaponControllerFREE>();
            rpgCharacterInputControllerFREE    = gameObject.AddComponent <RPGCharacterInputControllerFREE>();

            //Setup Animator, add AnimationEvents script.
            animator = GetComponentInChildren <Animator>();
            if (animator == null)
            {
                Debug.LogError("ERROR: THERE IS NO ANIMATOR COMPONENT ON CHILD OF CHARACTER.");
                Time.timeScale = 0f;
                Destroy(this);
                return;
            }
            else if (!animator.isHuman)
            {
                Debug.LogError("ERROR: CHARACTER AVATAR RIG IS NOT HUMANOID.");
                Time.timeScale = 0f;
                Destroy(this);
                return;
            }
            else
            {
                animator.gameObject.AddComponent <RPGCharacterAnimatorEventsFREE>();
                animator.GetComponent <RPGCharacterAnimatorEventsFREE>().rpgCharacterController = this;
                animator.gameObject.AddComponent <AnimatorParentMoveFREE>();
                animator.GetComponent <AnimatorParentMoveFREE>().anim = animator;
                animator.GetComponent <AnimatorParentMoveFREE>().rpgCharacterMovementController = rpgCharacterMovementControllerFREE;
                animator.updateMode  = AnimatorUpdateMode.AnimatePhysics;
                animator.cullingMode = AnimatorCullingMode.CullUpdateTransforms;
            }

            ikHandsFREE = GetComponentInChildren <IKHandsFREE>();

            //Set for starting Unarmed state.
            weapon = Weapon.UNARMED;
            animator.SetInteger("Weapon", 0);
            animator.SetInteger("WeaponSwitch", -1);
            StartCoroutine(_ResetIdleTimer());
        }