void Update() { float h = Input.GetAxis("Horizontal"); // setup h variable as our horizontal input axis float v = Input.GetAxis("Vertical"); // setup v variables as our vertical input axis anim.SetFloat("Speed", v); // set our animator's float parameter 'Speed' equal to the vertical input axis anim.SetFloat("Direction", h); // set our animator's float parameter 'Direction' equal to the horizontal input axis anim.speed = animSpeed; // set the speed of our animator to the public variable 'animSpeed' // anim.SetLookAtWeight(lookWeight); // set the Look At Weight - amount to use look at IK vs using the head's animation currentBaseState = anim.GetCurrentAnimatorStateInfo(0); // set our currentState variable to the current state of the Base Layer (0) of animation // float vol = Random.Range (volLowRange, volHighRange); //throwMechanics.throwBall (Input.GetButtonUp ("Fire1")); if (anim.layerCount == 2) { layer2CurrentState = anim.GetCurrentAnimatorStateInfo(1); // set our layer2CurrentState variable to the current state of the second Layer (1) of animation } if (currentBaseState.nameHash == idleState) { if (Input.GetKeyDown(KeyCode.V)) { anim.SetTrigger("Attack"); Ray ray1 = new Ray(transform.position + Vector3.up, transform.forward); Debug.DrawRay(transform.position + Vector3.up, transform.forward); RaycastHit objectHit = new RaycastHit(); if (Physics.Raycast(ray1, out objectHit)) { if (objectHit.distance <= 2f && objectHit.transform.CompareTag("npc")) { // push = objectHit.transform.gameObject.GetComponent<AddForcetoObject> (); // push.addForce(); npcTakeDamage.takeDamage(); } } } } // if (currentBaseState.nameHash == attackState) { // if (Input.GetKey (KeyCode.V)) { // anim.SetBool ("Attack", true); // } // } if (currentBaseState.nameHash == locoState) { // audioSource.Play(); if (Input.GetKey(KeyCode.C)) { anim.SetBool("Crouch", true); } if (!(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))) { float s = anim.GetFloat("Speed"); anim.SetFloat("Speed", s / 4); } } else if (currentBaseState.nameHash == crouchState) { audioSource.Stop(); if (Input.GetKey(KeyCode.C)) { anim.SetBool("Crouch", false); } } else if (currentBaseState.nameHash == crouchWalkState) { audioSource.Stop(); if (Input.GetKey(KeyCode.C)) { anim.SetBool("Crouch", false); } } // STANDARD JUMPING // if we are currently in a state called Locomotion (see line 25), then allow Jump input (Space) to set the Jump bool parameter in the Animator to true if (currentBaseState.nameHash == locoState) { if (Input.GetButtonDown("Jump")) { anim.SetBool("Jump", true); } } // if we are in the jumping state... else if (currentBaseState.nameHash == jumpState) { // ..and not still in transition.. if (!anim.IsInTransition(0)) { if (useCurves) { // ..set the collider height to a float curve in the clip called ColliderHeight col.height = anim.GetFloat("ColliderHeight"); } // reset the Jump bool so we can jump again, and so that the state does not loop anim.SetBool("Jump", false); } // Raycast down from the center of the character.. Ray ray = new Ray(transform.position + Vector3.up, -Vector3.up); RaycastHit hitInfo = new RaycastHit(); if (Physics.Raycast(ray, out hitInfo)) { // ..if distance to the ground is more than 1.75, use Match Target if (hitInfo.distance > 1.75f) { // MatchTarget allows us to take over animation and smoothly transition our character towards a location - the hit point from the ray. // Here we're telling the Root of the character to only be influenced on the Y axis (MatchTargetWeightMask) and only occur between 0.35 and 0.5 // of the timeline of our animation clip anim.MatchTarget(hitInfo.point, Quaternion.identity, AvatarTarget.Root, new MatchTargetWeightMask(new Vector3(0, 1, 0), 0), 0.35f, 0.5f); } } } if (Input.GetKeyDown(KeyCode.E)) { Ray ray1 = new Ray(transform.position + Vector3.up, transform.forward); Debug.DrawRay(transform.position + Vector3.up, transform.forward); RaycastHit objectHit = new RaycastHit(); if (Physics.Raycast(ray1, out objectHit)) { if (objectHit.distance <= 2f && objectHit.transform.tag == "Interactable") { // push = objectHit.transform.gameObject.GetComponent<AddForcetoObject> (); // push.addForce(); } } } }