private void OnTriggerEnter(Collider other) { AnimatorStateInfo?info = m_stateMachine?.GetCurrentAnimatorStateInfo(0); if (info == null) { return; } if (Vector3.Distance(transform.position, m_pirateIslandTransform.position) < m_distanceToPirateIslandThreshold) { if (info.Value.IsName("Combat") || info.Value.IsName("Chase")) { m_stateMachine.SetTrigger("NearPirateIsland"); } } else if (other.gameObject.GetComponent <Player>() != null) { m_stateMachine.SetTrigger("PlayerIsSighted"); } else if (m_escortee != null && other.gameObject.GetComponent <Ship>() && other.gameObject.GetComponent <Ship>().m_category == ShipSystem.ShipCategory.Merchant) { if (!info.Value.IsName("Combat")) { m_stateMachine.SetTrigger("FoundMerchantShip"); m_escortee = other.gameObject; } } }
// Use this for initialization void Start() { anim = GetComponent <Animator> (); Destroy(gameObject, anim.GetCurrentAnimatorStateInfo(0).length); }
// Update is called once per frame void Update() { // Get currently playing animation AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0); // Make the asset to always face the player - only rotate on y axis var lookPos = player.transform.position - transform.position; lookPos.y = 0; var rotation = Quaternion.LookRotation(lookPos); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, 1f); // Get distance from player float distance = Vector3.Distance(player.transform.position, transform.position); // Get player direction from goblin Vector3 direction = player.transform.position - transform.position; RaycastHit hit; if (Physics.Raycast(transform.position, direction.normalized, out hit, lookRadius) && aggro == false) { //aggro if the player is seen //Debug.DrawRay(transform.position, direction.normalized * 100000f, Color.red, 20f); if (hit.collider.gameObject == player) { aggro = true; } } // Calculate by distance whether to walk towards the player or melee attack if (aggro && distance > meleeRadius) { agent.SetDestination(player.transform.position); animator.SetBool("Walk", true); animator.SetBool("Attack", false); attackDelay = defaultAttackDelay; } else if (distance <= meleeRadius) { attackDelay -= Time.deltaTime; if (distance <= meleeRadius * 0.6f) { agent.SetDestination(transform.position); } animator.SetBool("Attack", true); animator.SetBool("Walk", false); // Shoot raycast forward to deal damage to the player RaycastHit hit1; //Debug.DrawRay(transform.position + Vector3.down, transform.rotation * Vector3.forward, Color.green, extendedMeleeRadius); if (Physics.Raycast(transform.position + Vector3.down, transform.rotation * Vector3.forward, out hit1, extendedMeleeRadius)) { if (hit1.collider.gameObject == player && attackDelay <= 0 && info.IsName("GoblinAttack")) { playerController.TakeDamage(damage); attackDelay = defaultAttackDelay; } } } else { attackDelay = defaultAttackDelay; } }
// Update is called once per frame void Update() { // Update character state switch (state) { case CharacterState.idle: if (!hasEnteredNewState) { hasEnteredNewState = true; characterAnimator.Play(animNameIdle); } // Exit if (PlayerPressedInput()) { EnterNewState(CharacterState.walking); } break; case CharacterState.walking: if (!hasEnteredNewState) { hasEnteredNewState = true; if (isControlled) { characterAnimator.Play(animNameWalking); } } // Exit if (!PlayerPressedInput()) { EnterNewState(CharacterState.idle); } break; case CharacterState.death: if (!hasEnteredNewState && isAlive) { hasEnteredNewState = true; monsterBiteAnim.Play("MonsterBite"); characterAnimator.Play(animNameIdle); StartCoroutine(GameObject.FindWithTag("MainCamera").GetComponent <Player>().ShakeScreen(0.3f)); isAlive = false; lineRenderer.enabled = false; cursor.SetActive(false); characterSprite.flipX = false; managerUI.Pickup(false); UIHead.SetActive(false); } // Check anim finished if (monsterBiteAnim.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1 && monsterBiteAnim.GetCurrentAnimatorStateInfo(0).IsName("MonsterBite")) { // Finished characterAnimator.enabled = false; characterSprite.gameObject.transform.localEulerAngles = new Vector3(0, 0, 90); characterSprite.gameObject.transform.localPosition = new Vector3(0, 1.73f, 0); } break; default: break; } if (!isControlled) { lineRenderer.enabled = false; } if (!isControlled) { return; } if (!isAlive) { return; } if (!canMove) { return; } // Movement moveDir = Vector3.zero; if (controller.isGrounded) { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); // Flip sprite if (h == 1) { characterSprite.flipX = false; } else if (h == -1) { characterSprite.flipX = true; } moveDir = (v * Vector3.forward + h * Vector3.right).normalized; moveDir *= characterSpeed; } moveDir.y -= gravity; CheckGround(); ControllCharacter(); // Trowing if (!isHidden) { LaunchProjectile(); } if (isHidden) { lineRenderer.enabled = false; } else { if (Input.GetMouseButtonDown(1)) { if (trowableAmount > 0) { lineRenderer.enabled = true; } } } // Target Target.show = lineRenderer.enabled; // Enable/Disable cursor cursor.SetActive(lineRenderer.enabled); }
void OnControllerColliderHit(ControllerColliderHit hit) { conveyorVec = Vector3.zero; if (hit.gameObject.layer == LayerMask.NameToLayer("KillFloor")) { CharacterController controller = GetComponent <CharacterController>(); controller.detectCollisions = false; canMove = false; controller.Move(currCheckpoint - transform.position); canMove = true; controller.detectCollisions = true; } //if player hits a checkpoint, set corresponding bool to true and canMove to false so proper text can be displayed if (hit.gameObject.layer == LayerMask.NameToLayer("Checkpoint")) { if (hit.gameObject.tag == "Checkpoint1") { startText1 = true; canMove = false; } else if (hit.gameObject.tag == "Checkpoint2") { startText2 = true; canMove = false; } else if (hit.gameObject.tag == "Checkpoint3") { startText3 = true; canMove = false; } else if (hit.gameObject.tag == "Checkpoint4") { startText4 = true; canMove = false; } else if (hit.gameObject.tag == "Checkpoint5") { startText5 = true; canMove = false; } else if (hit.gameObject.tag == "Checkpoint6") { startText6 = true; canMove = false; } else if (hit.gameObject.tag == "Checkpoint7") { startText7 = true; canMove = false; } currCheckpoint = hit.transform.position; Vector3 temp = hit.transform.position; temp.y -= 2; currCheckpoint = temp; Destroy(hit.gameObject); } //if collided with a key if (hit.transform.tag == "Collectible") { hit.transform.SendMessage("Collided"); doneWithIntroText = true; } //if player is on a conveyor belt, change velocity/ velocity direction if (hit.transform.tag == "Conveyer") { Vector3 dir = Vector3.right; dir = Quaternion.Euler(0, hit.transform.eulerAngles.y, 0) * dir; dir.Normalize(); conveyorVec = dir; } if (controller.isGrounded) { if (!alreadyHit) { anim.Play("jumpDown"); } alreadyHit = true; } else { alreadyHit = false; } if (hit.transform.tag == "Bottle" && anim.GetCurrentAnimatorStateInfo(0).shortNameHash == whipHash) { Destroy(hit.gameObject); } if (hit.transform.tag == "Machine" && anim.GetCurrentAnimatorStateInfo(0).shortNameHash == whipHash) { SystemManager.LoadGivenScene("EndScene"); } isWhipping = anim.GetCurrentAnimatorStateInfo(0).shortNameHash == whipHash; }
private CinemachineVirtualCameraBase ChooseCurrentCamera(float deltaTime) { //UnityEngine.Profiling.Profiler.BeginSample("CinemachineStateDrivenCamera.ChooseCurrentCamera"); if (m_ChildCameras == null || m_ChildCameras.Length == 0) { mActivationTime = 0; //UnityEngine.Profiling.Profiler.EndSample(); return(null); } CinemachineVirtualCameraBase defaultCam = m_ChildCameras[0]; if (m_AnimatedTarget == null || !m_AnimatedTarget.gameObject.activeSelf || m_AnimatedTarget.runtimeAnimatorController == null || m_LayerIndex < 0 || m_LayerIndex >= m_AnimatedTarget.layerCount) { mActivationTime = 0; //UnityEngine.Profiling.Profiler.EndSample(); return(defaultCam); } // Get the current state int hash; if (m_AnimatedTarget.IsInTransition(m_LayerIndex)) { // Force "current" state to be the state we're transitionaing to AnimatorStateInfo info = m_AnimatedTarget.GetNextAnimatorStateInfo(m_LayerIndex); hash = info.fullPathHash; if (m_AnimatedTarget.GetNextAnimatorClipInfoCount(m_LayerIndex) > 1) { m_AnimatedTarget.GetNextAnimatorClipInfo(m_LayerIndex, m_clipInfoList); hash = GetClipHash(info.fullPathHash, m_clipInfoList); } } else { AnimatorStateInfo info = m_AnimatedTarget.GetCurrentAnimatorStateInfo(m_LayerIndex); hash = info.fullPathHash; if (m_AnimatedTarget.GetCurrentAnimatorClipInfoCount(m_LayerIndex) > 1) { m_AnimatedTarget.GetCurrentAnimatorClipInfo(m_LayerIndex, m_clipInfoList); hash = GetClipHash(info.fullPathHash, m_clipInfoList); } } // If we don't have an instruction for this state, find a suitable default while (hash != 0 && !mInstructionDictionary.ContainsKey(hash)) { hash = mStateParentLookup.ContainsKey(hash) ? mStateParentLookup[hash] : 0; } float now = Time.time; if (mActivationTime != 0) { // Is it active now? if (mActiveInstruction.m_FullHash == hash) { // Yes, cancel any pending mPendingActivationTime = 0; //UnityEngine.Profiling.Profiler.EndSample(); return(mActiveInstruction.m_VirtualCamera); } // Is it pending? if (deltaTime >= 0) { if (mPendingActivationTime != 0 && mPendingInstruction.m_FullHash == hash) { // Has it been pending long enough, and are we allowed to switch away // from the active action? if ((now - mPendingActivationTime) > mPendingInstruction.m_ActivateAfter && ((now - mActivationTime) > mActiveInstruction.m_MinDuration || mPendingInstruction.m_VirtualCamera.Priority > mActiveInstruction.m_VirtualCamera.Priority)) { // Yes, activate it now mActiveInstruction = mPendingInstruction; mActivationTime = now; mPendingActivationTime = 0; } //UnityEngine.Profiling.Profiler.EndSample(); return(mActiveInstruction.m_VirtualCamera); } } } // Neither active nor pending. mPendingActivationTime = 0; // cancel the pending, if any if (!mInstructionDictionary.ContainsKey(hash)) { // No defaults set, we just ignore this state if (mActivationTime != 0) { return(mActiveInstruction.m_VirtualCamera); } //UnityEngine.Profiling.Profiler.EndSample(); return(defaultCam); } // Can we activate it now? Instruction newInstr = m_Instructions[mInstructionDictionary[hash]]; if (newInstr.m_VirtualCamera == null) { newInstr.m_VirtualCamera = defaultCam; } if (deltaTime >= 0 && mActivationTime > 0) { if (newInstr.m_ActivateAfter > 0 || ((now - mActivationTime) < mActiveInstruction.m_MinDuration && newInstr.m_VirtualCamera.Priority <= mActiveInstruction.m_VirtualCamera.Priority)) { // Too early - make it pending mPendingInstruction = newInstr; mPendingActivationTime = now; if (mActivationTime != 0) { return(mActiveInstruction.m_VirtualCamera); } //UnityEngine.Profiling.Profiler.EndSample(); return(defaultCam); } } // Activate now mActiveInstruction = newInstr; mActivationTime = now; //UnityEngine.Profiling.Profiler.EndSample(); return(mActiveInstruction.m_VirtualCamera); }
void Update() { childcounterM = Mouse.transform.childCount; childcounterR = Rightarm.transform.childCount; childcounterL = Leftarm.transform.childCount; if (childcounterR > 0) { ChildR = Rightarm.gameObject.transform.GetChild(0); } if (childcounterL > 0) { ChildL = Leftarm.gameObject.transform.GetChild(0); } if (Input.GetKey(KeyCode.E)) { Healing(); } Eating(); Waterfill(); Drinking(); TakeItemR(); TakeItemL(); //*****************************************************************// // HIER WERKZEUGANIMATIONEN EINFÜGEN // //*****************************************************************// // Werkzeuganimationen----------------------------------------------------------- // Axt if (childcounterR > 0 && ChildR.name.Contains("Axe")) { Workanimation("pickaxeR", null); } if (childcounterL > 0 && ChildL.name.Contains("Axe")) { Workanimation(null, "pickaxeL"); } //Spitzhacke if (childcounterR > 0 && ChildR.name.Contains("Pickaxe")) { Workanimation("pickaxeR", null); } if (childcounterL > 0 && ChildL.name.Contains("Pickaxe")) { Workanimation(null, "pickaxeL"); } // Angel if (childcounterR > 0 && ChildR.name.Contains("Rod")) { Workanimation("fishing", null); } // Waffenanimation----------------------------------------------------------- // Holzschwert if (childcounterR > 0 && ChildR.name.Contains("Sword")) { Workanimation("pickaxeR", null); } if (childcounterL > 0 && ChildL.name.Contains("Sword")) { Workanimation(null, "pickaxeL"); } // Bogen if (childcounterL > 0 && ChildL.name.Contains("Bow") && pfeil) { Workanimation(null, "bogen"); } //Speer if (childcounterR > 0 && ChildR.name.Contains("Spear")) { Workanimation("speerR", null); } if (childcounterL > 0 && ChildL.name.Contains("Spear")) { Workanimation(null, "speerL"); } // Menu Öffnen if (Input.GetKeyDown(KeyCode.Escape)) { PauseMenu.SetActive(!PauseMenu.activeSelf); } if (PauseMenu.activeSelf == true) { pause = true; } else { pause = false; } // if(pause && !mySaveGameSettings.loading) {Time.timeScale = 0f;} // else{Time.timeScale = 1f;} // Inventar öffnen---------------------------------------------------------------- if (Input.GetKeyDown(KeyCode.I) && Inventarbool == false) { InventoryPanel.transform.localPosition = new Vector3(-500, 200); Inventarbool = true; } else if (Input.GetKeyDown(KeyCode.I) && Inventarbool == true) { InventoryPanel.transform.localPosition = new Vector3(-500, 2000); Inventarbool = false; } // Handwerk öffnen if (Input.GetKeyDown(KeyCode.C) && Rezeptbool == false) { RezeptPanel.transform.localPosition = new Vector3(-200, 60); Rezeptbool = true; } else if (Input.GetKeyDown(KeyCode.C) && Rezeptbool == true) { RezeptPanel.transform.localPosition = new Vector3(-500, 3000); Rezeptbool = false; } // Equipment öffnen if (Input.GetKeyDown(KeyCode.J) && Equipmentbool == false) { EquipmentPanel.transform.localPosition = new Vector3(-500, -100); Equipmentbool = true; } else if (Input.GetKeyDown(KeyCode.J) && Equipmentbool == true) { EquipmentPanel.transform.localPosition = new Vector3(-500, 4000); Equipmentbool = false; } // MouseSlot anzeigen if (childcounterM > 0) { MouseSlot.SetActive(true); } else { MouseSlot.SetActive(false); } // Charaktersteuerung if (animator.GetCurrentAnimatorStateInfo(0).IsName("eating") || animator.GetCurrentAnimatorStateInfo(0).IsName("drinking") || animator.GetCurrentAnimatorStateInfo(0).IsName("fishing") || animator.GetCurrentAnimatorStateInfo(0).IsName("TakeFish") || animator.GetCurrentAnimatorStateInfo(0).IsName("TakeItemR") || animator.GetCurrentAnimatorStateInfo(0).IsName("TakeItemL") || animator.GetCurrentAnimatorStateInfo(0).IsName("waterfill") || animator.GetCurrentAnimatorStateInfo(0).IsName("death")) { } else { var move = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0); Charakter.transform.position += move * speed * Time.deltaTime; } // Charakter drehen (flip) ------------------------------------- if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.Space) && !death) { setleft = true; } if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.Space) && !death) { setleft = false; } if (setleft == true) { Charakter.transform.localScale = new Vector3(-1, 1, 1); } else { Charakter.transform.localScale = new Vector3(1, 1, 1); } // Walk Animation if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D)) { animator.SetBool("run", true); } else { animator.SetBool("run", false); } }
// Update is called once per frame void Update() { dodgeCount = 0; animState = anim.GetCurrentAnimatorStateInfo(0); grounded = Physics2D.Linecast(transform.position, groundCheck.position, (1 << LayerMask.NameToLayer("ground")) | (1 << LayerMask.NameToLayer("Enemy"))); /* * if (animState.IsName(IdelState) && HitCount != 0 && animState.normalizedTime > 0f) * { * HitCount = 0; * anim.SetInteger("attackcount", HitCount); * * } */ if (HitCount != 0 && animState.normalizedTime > 1f) { HitCount = 0; //anim.SetFloat("attackcount", HitCount); } /* * if (anim.IsInTransition(0)) * { * HitCount = 0; * anim.SetFloat("attackcount", HitCount); * * } */ if (animState.IsName(IdelState) && chargeTotal != 0 && animState.normalizedTime > 0f) { chargeTotal = 0; isDown = false; anim.SetFloat("charge", chargeTotal); anim.ResetTrigger("chargeattack"); Debug.Log("ccc"); } if (Input.GetButtonDown("lightattack")) { attackcommand(); } if (Input.GetButtonDown("heavyattack") && grounded && !isTransform && GetComponent <getHurt>().SPthreata > 0) { if (animState.IsName(WalkState) || animState.IsName(IdelState)) { canmove = false; attack = true; t1 = Time.time; isDown = true; anim.SetTrigger("ischarge"); } //heavyattackcommand(); } if (isDown) { t_detal = Time.time; chargeTotal = (t_detal - t1) * chargeSpd; anim.SetFloat("charge", chargeTotal); if (chargeTotal >= chargeMax) { anim.SetTrigger("chargeattack"); isDown = false; chargeTotal = 0; } } if (Input.GetButtonUp("heavyattack") && chargeTotal != 0 && !isTransform && GetComponent <getHurt>().SPthreata > 0) { isDown = false; t2 = Time.time; chargeTotal = (t2 - t1) * chargeSpd; anim.SetFloat("charge", chargeTotal); anim.SetTrigger("chargeattack"); //isDown = false; chargeTotal = 0; } //闪避 if (Input.GetButtonDown("dodge") && GetComponent <getHurt>().SPthreata > 0 && grounded) { float inputspeed = Input.GetAxis("Horizontal"); if (Mathf.Abs(inputspeed) > 0) { anim.SetTrigger("isDodge"); dodgeCount += 1; } else { anim.SetTrigger("isDodgeback"); dodgeCount += 1; } } if (Input.GetButtonDown("Jump") && !isfall && grounded && canmove) { jump = true; } if (Input.GetButtonDown("transform")) { anim.SetTrigger("istransform"); } }
private void Update() { if (cekMan) { blockMe.SetActive(false); if (_manageAnimator.GetCurrentAnimatorStateInfo(0).IsName("OnOut") && _manageAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f) { Manage.SetActive(false); cekMan = false; } } if (cekque) { blockMe.SetActive(false); if (quitPanel.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("OnOut") && quitPanel.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f) { quitPanel.SetActive(false); cekque = false; } } if (cekmes) { blockMe.SetActive(false); if (pesanPanel.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("OnOut") && pesanPanel.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f) { pesanPanel.SetActive(false); cekmes = false; escapeKill = false; } } if (cekcon) { blockMe.SetActive(false); if (connection.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("OnOut") && connection.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f) { connection.SetActive(false); cekcon = false; escapeKill = false; } } #region backscape if (Input.GetKeyDown(KeyCode.Escape) && !escapeKill) { if (quitPanel.activeInHierarchy) { playOnClick(); HideQuite(); } else { playOnClick(); if (!Manage.activeInHierarchy) { ShowQuit(); } else { BackManage(); } } } #endregion backscape }
void Update() { if (!valid) { return; } if (layerMixModes.Length != animator.layerCount) { System.Array.Resize <MixMode>(ref layerMixModes, animator.layerCount); } float deltaTime = Time.time - lastTime; skeleton.Update(Time.deltaTime); //apply int layerCount = animator.layerCount; for (int i = 0; i < layerCount; i++) { float layerWeight = animator.GetLayerWeight(i); if (i == 0) { layerWeight = 1; } var stateInfo = animator.GetCurrentAnimatorStateInfo(i); var nextStateInfo = animator.GetNextAnimatorStateInfo(i); #if UNITY_5 var clipInfo = animator.GetCurrentAnimatorClipInfo(i); var nextClipInfo = animator.GetNextAnimatorClipInfo(i); #else var clipInfo = animator.GetCurrentAnimatorClipInfo(i); var nextClipInfo = animator.GetNextAnimatorClipInfo(i); #endif MixMode mode = layerMixModes[i]; if (mode == MixMode.AlwaysMix) { //always use Mix instead of Applying the first non-zero weighted clip for (int c = 0; c < clipInfo.Length; c++) { AnimatorClipInfo info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } float time = stateInfo.normalizedTime * info.clip.length; animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, events, weight); #if USE_SPINE_EVENTS FireEvents(events, weight, this.AnimationEvent); #endif } #if UNITY_5 if (nextStateInfo.fullPathHash != 0) { #else if (nextStateInfo.nameHash != 0) { #endif for (int c = 0; c < nextClipInfo.Length; c++) { AnimatorClipInfo info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } float time = nextStateInfo.normalizedTime * info.clip.length; animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, events, weight); #if USE_SPINE_EVENTS FireEvents(events, weight, this.AnimationEvent); #endif } } } else if (mode >= MixMode.MixNext) { //apply first non-zero weighted clip int c = 0; for (; c < clipInfo.Length; c++) { AnimatorClipInfo info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } float time = stateInfo.normalizedTime * info.clip.length; animationTable[GetAnimationClipNameHashCode(info.clip)].Apply(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, events); #if USE_SPINE_EVENTS FireEvents(events, weight, this.AnimationEvent); #endif break; } //mix the rest for (; c < clipInfo.Length; c++) { AnimatorClipInfo info = clipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } float time = stateInfo.normalizedTime * info.clip.length; animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, events, weight); #if USE_SPINE_EVENTS FireEvents(events, weight, this.AnimationEvent); #endif } c = 0; #if UNITY_5 if (nextStateInfo.fullPathHash != 0) { #else if (nextStateInfo.nameHash != 0) { #endif //apply next clip directly instead of mixing (ie: no crossfade, ignores mecanim transition weights) if (mode == MixMode.SpineStyle) { for (; c < nextClipInfo.Length; c++) { AnimatorClipInfo info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } float time = nextStateInfo.normalizedTime * info.clip.length; animationTable[GetAnimationClipNameHashCode(info.clip)].Apply(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, events); #if USE_SPINE_EVENTS FireEvents(events, weight, this.AnimationEvent); #endif break; } } //mix the rest for (; c < nextClipInfo.Length; c++) { AnimatorClipInfo info = nextClipInfo[c]; float weight = info.weight * layerWeight; if (weight == 0) { continue; } float time = nextStateInfo.normalizedTime * info.clip.length; animationTable[GetAnimationClipNameHashCode(info.clip)].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, events, weight); #if USE_SPINE_EVENTS FireEvents(events, weight, this.AnimationEvent); #endif } } } } if (_UpdateLocal != null) { _UpdateLocal(this); } skeleton.UpdateWorldTransform(); if (_UpdateWorld != null) { _UpdateWorld(this); skeleton.UpdateWorldTransform(); } if (_UpdateComplete != null) { _UpdateComplete(this); } lastTime = Time.time; }
void Update() { projectileDamage = Random.Range(50, 60); timer += Time.deltaTime; //fire pod153 if (Input.GetMouseButton(1) && timer > spawnInterval) { if (flag0 == false) { //trigger starting fire animation, play fire start audio clip podAnim.SetBool("FireStart", true); if (podAnim.GetBool("Fired") == true && flag4 == false) { podAnim.SetBool("Firing", true); audioSource.PlayOneShot(fireStartClip); flag4 = true; } flag0 = true; flag1 = false; } //wait for firing animation, play audio clip, create projectile if (podAnim.GetCurrentAnimatorStateInfo(0).IsName("Pod153Firing")) { if (flag2 == false) { //play firing audio clip audioSource.PlayOneShot(firingClip); podAnim.SetBool("FireStart", false); podAnim.SetBool("Firing", false); flag2 = true; } Instantiate(projectilePrefab, transform.position, podMovementReference.transform.rotation); } timer = 0; } if (!Input.GetMouseButton(1)) { //trigger closing fire animation, reset flags and animation parameter values podAnim.SetBool("FireStart", false); podAnim.SetBool("Firing", false); podAnim.SetBool("Fired", true); flag0 = false; } if (podAnim.GetCurrentAnimatorStateInfo(0).IsName("Pod153FireEnd")) { podAnim.SetBool("Fired", false); flag2 = false; flag3 = false; flag4 = false; } }
private void Start() { AniInfo = NextTurnAnimation.GetCurrentAnimatorStateInfo(0); Init(); }
void Update() { AnimatorStateInfo stateInfo = m_animator.GetCurrentAnimatorStateInfo(0); float currentRatio = stateInfo.normalizedTime * stateInfo.length; if (GetComponent <MercenaryHealth>().IsDie) { if (stateInfo.IsName("Recharge")) { foreach (ParticleSystem p in m_particles) { p.gameObject.SetActive(false); } } if (!isdie) { isdie = true; //m_nvAgent.enabled = false; GetComponent <Collider>().enabled = false; m_animator.SetTrigger("Die"); } else { if (stateInfo.IsName("Die") && currentRatio >= stateInfo.length * 0.80f) { m_animator.speed = 0; } } return; } float dis = Vector3.Distance(m_player.transform.position, transform.position); if (attackCheck) { m_skill1CoolTime -= Time.deltaTime; int targetCount = 0; if (m_target == null) { Collider[] collider = Physics.OverlapSphere(transform.position, 6.0f); foreach (Collider col in collider) { if (col.gameObject.tag == "Monster" || col.gameObject.tag == "Boss") { if (col.GetComponent <MonsterHealth>().IsDie) { continue; } float distance = Vector3.Distance(transform.position, col.transform.position); if (distance < m_distance) { m_target = col; m_distance = distance; targetCount++; } } if (targetCount == 0) { m_target = null; } } } if (dis >= 7.0f) { m_nvAgent.SetDestination(m_player.transform.position); m_animator.SetBool("Run", true); m_animator.SetBool("MeleeAttack", false); } else if (m_target != null) { if (!m_target.GetComponent <MonsterHealth>().IsDie) { float distance = Vector3.Distance(transform.position, m_target.transform.position); if (distance <= m_attackRange) { m_animator.SetBool("Run", false); m_nvAgent.velocity = Vector3.zero; if (m_skill1CoolTime <= 0 && !m_animator.IsInTransition(0) && !skill1Check) { skill1Check = true; m_animator.SetBool("MeleeAttack", false); transform.LookAt(m_target.transform.position); m_animator.SetBool("Recharge", true); m_nvAgent.isStopped = true; foreach (ParticleSystem p in m_particles) { p.gameObject.SetActive(true); p.Play(); } m_skill1CoolTime = 10.0f; Invoke("StopMagicianSkill1", 5.0f); } else if (!skill1Check) { if (!stateInfo.IsName("Recharge") && !m_animator.IsInTransition(0)) { transform.LookAt(m_target.transform); m_animator.SetBool("MeleeAttack", true); } } } else { if ((!stateInfo.IsName("MeleeAttack") || !stateInfo.IsName("Recharge")) && !m_animator.IsInTransition(0)) { if (m_nvAgent.isActiveAndEnabled) { m_nvAgent.SetDestination(m_target.transform.position); m_animator.SetBool("Run", true); } } } } else { m_target = null; m_distance = 100.0f; } } else if (m_target == null) { m_animator.SetBool("MeleeAttack", false); if (dis < 3.0f) { m_animator.SetBool("Run", false); } else if (!stateInfo.IsName("Recharge")) { m_nvAgent.SetDestination(m_player.transform.position); m_animator.SetBool("Run", true); } } else { m_animator.SetBool("MeleeAttack", false); } } else { if (dis > 3.0f && !stateInfo.IsName("Recharge")) { if (!m_nvAgent.isActiveAndEnabled) { m_nvAgent.enabled = true; } m_nvAgent.SetDestination(m_player.transform.position); m_animator.SetBool("Run", true); } else { m_animator.SetBool("Run", false); m_nvAgent.velocity = Vector3.zero; //attackCheck = true; } } if (skill1Check) { time += Time.deltaTime; if (time >= 0.8f) { MagicianFirstSkill(); time = 0.0f; } } m_str = m_player.GetComponent <CharController>().GetTotalStr * 0.8f; m_oriHp = m_player.GetComponent <CharController>().GetTotalHp * 0.8f; if (isHitBack) { if (m_hitBackTime < 0.0f) { m_nvAgent.enabled = true; isHitBack = false; m_hitBackTime = 0.1f; return; } m_nvAgent.enabled = false; transform.Translate(-Vector3.forward * Time.deltaTime * 8.0f); m_hitBackTime -= Time.deltaTime; } }
// Update is called once per frame void Update() { if (forcePushBool && Time.time > forcePushTimer) { forcePushBool = false; //GameObject player = GameObject.Find("Player"); victor.rigidbody.AddForce(pushForce * transform.forward); attacking = false; } float step = rotationSpeed * Time.deltaTime; targetDirection.y = 0; Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDirection, step, 0.0F); transform.rotation = Quaternion.LookRotation(newDir); //Get state from animation AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0); //If in attack state, set attacking to false if (stateInfo.nameHash == Animator.StringToHash("Base Layer.Attack")) { animator.SetBool("Attacking", false); //GameObject player = GameObject.Find("Player"); setTargetRotationTransform(victor.transform); } //Patrolling //If waiting else if (stateInfo.nameHash == Animator.StringToHash("Base Layer.Idle") && walk == false) { if (Time.time > nextMove) //Start moving { indexCounter++; if (indexCounter > patrolPositions.GetLength(0) - 1) { indexCounter = 0; } nextPosition = new Vector3(patrolPositions[indexCounter].position.x, transform.position.y, patrolPositions[indexCounter].position.z); animator.SetBool("Walking", true); targetDirection = nextPosition - transform.position; walk = true; } } else if (walk = true) { //Move toward position transform.position += speed * Vector3.Normalize(nextPosition - transform.position); //Arrive if (Vector3.Distance(nextPosition, transform.position) < 1) { nextMove = Time.time + waitTime; animator.SetBool("Walking", false); targetDirection = patrolPositions[indexCounter].forward; walk = false; } } }
void Update() { float v = Input.GetAxis("Vertical"); float h = Input.GetAxis("Horizontal"); inf = anim.GetCurrentAnimatorStateInfo(0); if (inCar) { anim.SetFloat("Horizontal", h, .04f, Time.deltaTime); asientoCar.GetChild(0).localEulerAngles = new Vector3(asientoCar.GetChild(0).localEulerAngles.x, asientoCar.GetChild(0).localEulerAngles.y, h * 50); if (Input.GetKeyDown(KeyCode.F)) { car.GetComponent <Automovil>().encendido = false; car.GetComponent <Rigidbody>().drag = 2; anim.SetBool("Entrar", false); StartCoroutine("SalirDelAuto"); } } else { m_CamaraForward = Vector3.Scale(cam.forward, new Vector3(1, 0, 1)).normalized; Vector3 move = -v * m_CamaraForward + -h * cam.right; Vector3 move2 = v * m_CamaraForward + h * cam.right; if (caminandoToCar) { nav.SetDestination(target.position); if (nav.remainingDistance < nav.stoppingDistance) { caminandoToCar = false; nav.enabled = false; inPosition = true; //anim.applyRootMotion = true; //transform.rotation = target.rotation; //transform.position = target.position; car.GetComponent <Rigidbody>().drag = 0.1f; anim.SetTrigger("Abrir"); StartCoroutine("EntrarEnAuto"); } } if (Input.GetKeyDown(KeyCode.F)) { nav.enabled = true; nav.SetDestination(target.position); caminandoToCar = true; } if (lerpAsiento) { anim.MatchTarget(positionMatchTarget, rotationMatchTarget, AvatarTarget.Root, new MatchTargetWeightMask(Vector3.one, 1f), .0f); } if (!inPosition && !caminandoToCar) { Move(-move, true); } if (!inPosition && caminandoToCar) { //GetComponent<Rigidbody>().velocity = anim.velocity; Move(nav.desiredVelocity, false); if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0) { caminandoToCar = false; nav.enabled = false; } } } }
protected void Update() { if (startCombo && (animator.GetCurrentAnimatorStateInfo(0).IsName("Attack1") || animator.GetCurrentAnimatorStateInfo(0).IsName("Attack2") || animator.GetCurrentAnimatorStateInfo(0).IsName("Attack3"))) { player.CharacterControlDisabled = true; } else if (startCombo) { //player.CharacterControlDisabled = false; } if (Input.GetButtonDown("Attack") && !isAttacking && AttackMovementEnabled && !stopAttack) { if (Input.GetKey(KeyCode.UpArrow) && !floorDetector.isTouchingFloor) { SpecialAttackFromAir(); } else if (Input.GetKey(KeyCode.UpArrow)) { SpecialAttackFromGround(); } else { if (floorDetector.isTouchingFloor) { if (!firstAttackInJump) { attackCount = 0; firstAttackInJump = true; } if (startCombo) { CheckComboStage("Attack", "Attack2", "Attack3"); } else { attackCount = 0; audioManager.comboSound[0].Play(); audioManager.attackSound[Random.Range(0, 2)].Play(); CheckComboStage("Attack"); } } else { firstAttackInJump = true; if (startCombo) { CheckComboStage("Attack_In_Air", "Attack_In_Air2", "Attack_In_Air3"); } else { attackCount = 0; audioManager.comboSound[0].Play(); audioManager.attackSound[Random.Range(0, 1)].Play(); CheckComboStage("Attack_In_Air"); } } currentState = turnAround.isFacingLeft; StartAttackColldown(); } // Animation have to be played in same direction as on start } else if (stopAttack) { //Cant attack when knockback StartCoroutine(StopAttackDelay()); } }
// Update is called once per frame void Update() { horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed; if (Input.GetButtonDown("Jump")) { jump = true; } if (Input.GetButtonDown("Crouch")) { crouch = true; } if (Input.GetButtonUp("Crouch")) { crouch = false; } if (jump && !_isPlaying_Crouching && !controller.keepCrouch) { changeState(STATE_JUMPING); } else if (crouch && controller.m_Grounded || controller.keepCrouch) { changeState(STATE_CROUCHING); } else if (Input.GetAxisRaw("Horizontal") != 0 && !_isPlaying_Jumping && controller.m_Grounded && !controller.keepCrouch) { changeState(STATE_WALKING); } else { if (controller.m_Grounded) { changeState(STATE_IDLE); } } //Debug.Log(currentAnimationState); //if (animator.GetCurrentAnimatorStateInfo(0).IsName("Walking")) //{ // _isPlaying_Walking = true; //} //else _isPlaying_Walking = false; if (animator.GetCurrentAnimatorStateInfo(0).IsName("Jumping")) { _isPlaying_Jumping = true; } else { _isPlaying_Jumping = false; } if (animator.GetCurrentAnimatorStateInfo(0).IsName("Crouching")) { _isPlaying_Crouching = true; } else { _isPlaying_Crouching = false; } }
/** * Checks if the hero is currently sliding. * * @return True if the hero is curently in the Slide state. */ public bool IsSliding() { return(_anim.GetCurrentAnimatorStateInfo(0).IsName("Slide")); }
public void FindState() { if (m_Anim.GetCurrentAnimatorStateInfo(0).IsName("Attack")) { if (!isAttackRunning) { m_Anim.SetBool("Attack", false); Debug.Log("강제해제"); } } if (m_Anim.GetCurrentAnimatorStateInfo(0).IsName("Idle")) { isAttacking = false; isAttackRunning = false; isRun = false; } if ((isRun || isAttackRunning)) { return; } for (int idx = 0; idx < (int)AniType.Max; idx++) { if (m_Anim.GetBool(AniActionList[idx])) { if (idx == (int)AniType.Attack) { isAttacking = true; isRun = false; StartCoroutine("AttackAniCheck"); } else if (idx == (int)AniType.Run) { isRun = true; } else if (idx == (int)AniType.Idle) { isAttacking = false; isAttackRunning = false; isRun = false; } } else { if (idx == (int)AniType.Attack) { isAttacking = false; isAttackRunning = false; } else if (idx == (int)AniType.Run) { isRun = false; } m_Anim.SetBool(AniActionList[idx], false); } } }
public bool MostrarAnimacionCombate(AnimacionCombate animacion) { if (string.IsNullOrEmpty(ultimaAnimacionCombate)) { switch (animacion) { case AnimacionCombate.PokemonSalvajeAparece: ultimaAnimacionCombate = "CombatePokemonSalvaje"; break; case AnimacionCombate.EntrenadorEnviaPokemon: ultimaAnimacionCombate = "CombateEntrenadorEnviaPokemon"; break; case AnimacionCombate.JugadorEnviaPokemon: ultimaAnimacionCombate = "CombateJugadorEnviaPokemon"; break; case AnimacionCombate.LanzarPokeball: ultimaAnimacionCombate = "CombateLanzarPokeball"; break; case AnimacionCombate.PokeballSeAgita: ultimaAnimacionCombate = "CombatePokeballAgitarse"; break; case AnimacionCombate.PokeballSeRompe: ultimaAnimacionCombate = "CombatePokeballRomperse"; break; case AnimacionCombate.PokemonJugadorRecibeAtaque: ultimaAnimacionCombate = "CombatePokemonJugadorRecibeAtaque"; break; case AnimacionCombate.PokemonEnemigoRecibeAtaque: ultimaAnimacionCombate = "CombatePokemonEnemigoRecibeAtaque"; break; case AnimacionCombate.PokemonJugadorRealizaAtaqueFisico: ultimaAnimacionCombate = "CombatePokemonJugadorAtaqueFisico"; break; case AnimacionCombate.PokemonEnemigoRealizaAtaqueFisico: ultimaAnimacionCombate = "CombatePokemonEnemigoAtaqueFisico"; break; case AnimacionCombate.PokemonJugadorDerrotado: ultimaAnimacionCombate = "CombatePokemonJugadorDerrotado"; break; case AnimacionCombate.PokemonEnemigoDerrotado: ultimaAnimacionCombate = "CombatePokemonEnemigoDerrotado"; break; case AnimacionCombate.JugadorRetirarPokemon: ultimaAnimacionCombate = "CombateJugadorRetirarPokemon"; break; } animaciones.Play(ultimaAnimacionCombate); } if (animaciones.GetCurrentAnimatorStateInfo(0).IsName(ultimaAnimacionCombate) && animaciones.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f) { ultimaAnimacionCombate = string.Empty; animaciones.Play("PorDefecto"); return(false); } else { return(true); } }
public int GetStateFullHashPath() { return(_animator.GetCurrentAnimatorStateInfo(0).fullPathHash); }
void Update() { currentBaseState = animator.GetCurrentAnimatorStateInfo(0); float distance = Vector2.Distance(transform.position, player.position); /**************************************************/ /* A Simple State Machine Management starts here */ /************************************************/ if (currentBaseState.fullPathHash.Equals(walkState)) { hasAttacked = false; if (isChasing) { enemy.Resume(); setEnemyDirection(); isChasing = false; } // I have reached the previous player position or I have catched the player if (enemy.remainingDistance.Equals(0)) { setToThisAnimation(AnimationParams.isPunch); } } else if (currentBaseState.fullPathHash.Equals(punchState)) { if (!hasAttacked) { hasAttacked = true; enemy.Stop(); float pDistance = Vector2.Distance(transform.position, player.position); int attack = 2; audioE.clip = painSounds[attack]; audioE.Play(); if (pDistance <= 1.5f) { setEnemyDirection(); PlayerHealth.doDamage(damage, this.transform.position); playerCollider = null; } } setToThisAnimation(AnimationParams.isTired); } else if (currentBaseState.fullPathHash.Equals(tiredState)) { isTired = true; int quoteIndex = Random.Range(0, tiredList.Length); if (!isSaying) { isSaying = true; StartCoroutine(SaySomethingWhenTired(tiredList[quoteIndex])); } StartCoroutine(TimePause(timeBeforeChase)); } else if (currentBaseState.fullPathHash.Equals(beenHitState)) { // anything related to the beenHit state should locates here. animator.SetBool("isHit", false); isTired = true; } else if (currentBaseState.fullPathHash.Equals(roarState)) { if (isFirstTimeMeet) { isTired = false; isFirstTimeMeet = false; } else { isTired = true; } StartCoroutine(TimePause(timeBeforeChase)); StartToChase(); } else if (currentBaseState.fullPathHash.Equals(idleState)) { StartCoroutine(TimePause(timeBeforeChase)); StartToChase(); } else if (currentBaseState.fullPathHash.Equals(entryState)) { if (distance <= 4f) { //say something StartCoroutine(SaySomethingFirstMeet()); isFirstTimeMeet = false; enemy.Stop(); setToThisAnimation(AnimationParams.isRoar); StartCoroutine(TimePause(timeBeforeChase * 1.5f)); } } }
void Update() { forward = Input.GetKey(KeyCode.W); back = Input.GetKey(KeyCode.S); left = Input.GetKey(KeyCode.A); right = Input.GetKey(KeyCode.D); angle_to_rotete = 0; float jT = Mathf.Abs(anim.GetFloat("JumpingTiming") - 0.60f); Vector3 vector; RaycastHit hit; if (Physics.Raycast(transform.position, -Vector3.up, out hit, 0.5f)) { // Debug.Log("FFALSE " + hit.distance); anim.SetBool("inAir", false); } else { // Debug.Log("TRUE " + hit.distance); anim.SetBool("inAir", true); } //bool pla=Physics.Raycast(transform.position, -Vector3.up, distToGround, 0.1); int time = (int)(anim.GetFloat("JumpingTiming") * 100); if ((anim.GetCurrentAnimatorStateInfo(0).IsTag("jumpTag") || anim.GetCurrentAnimatorStateInfo(0).IsTag("jumpStaticTag")) && !anim.GetBool("inTheMiddleOfJumping")) { //move down vector = new Vector3(0, jT * jumpforce * Time.deltaTime, 0); transform.position -= vector; //move forward vector = new Vector3(jumpdist * Mathf.Sin(kat) * Time.deltaTime, 0, (jumpdist) * Mathf.Cos(kat) * Time.deltaTime); transform.position += vector; //move forward if (anim.GetCurrentAnimatorStateInfo(0).IsTag("jumpStaticTag")) { Debug.Log("wszedlem"); vector = new Vector3(0, 20 * Time.deltaTime, 0); transform.eulerAngles += vector; } } if ((anim.GetCurrentAnimatorStateInfo(0).IsTag("jumpTag") || anim.GetCurrentAnimatorStateInfo(0).IsTag("jumpStaticTag")) && anim.GetBool("inTheMiddleOfJumping")) { //move up vector = new Vector3(0, jT * jumpforce * Time.deltaTime, 0); transform.position += vector; //move forward vector = new Vector3(jumpdist * Mathf.Sin(kat) * Time.deltaTime, 0, (jumpdist) * Mathf.Cos(kat) * Time.deltaTime); transform.position += vector; //move forward if (anim.GetCurrentAnimatorStateInfo(0).IsTag("jumpStaticTag")) { Debug.Log("wszedlem"); vector = new Vector3(0, 20 * Time.deltaTime, 0); transform.eulerAngles += vector; } } if (activeMove) { anim.SetFloat("movement", Mathf.Max(Mathf.Abs(Input.GetAxis("Vertical")), Mathf.Abs(Input.GetAxis("Horizontal")))); if (anim.GetCurrentAnimatorStateInfo(0).IsTag("walkingWeap")) { transform.eulerAngles += new Vector3(0, Mathf.DeltaAngle(transform.eulerAngles.y, center_point.eulerAngles.y + angle_to_rotete) * Time.deltaTime * rotation_speed, 0); anim.SetFloat("y", Input.GetAxis("Vertical")); anim.SetFloat("x", Input.GetAxis("Horizontal")); } else { { if (Input.GetAxis("Jump") > 0.0f && !isInAir()) { anim.SetBool("jumping", true); if (anim.GetCurrentAnimatorStateInfo(0).IsTag("jumpTag")) { kat = transform.eulerAngles.y - 10; } else { kat = transform.eulerAngles.y; } kat *= 2.0f * 3.14f / 360.0f; } } anim.SetFloat("movement", Mathf.Max(Mathf.Abs(Input.GetAxis("Vertical")), Mathf.Abs(Input.GetAxis("Horizontal")))); if (anim.GetCurrentAnimatorStateInfo(0).IsTag("walking")) { calculate_angle(); transform.eulerAngles += new Vector3(0, Mathf.DeltaAngle(transform.eulerAngles.y, center_point.eulerAngles.y + angle_to_rotete) * Time.deltaTime * rotation_speed, 0); } } } }
private void HandleMouseClick( ) { // generate a ray from main camera to mouse Ray _ray = m_camera.ScreenPointToRay(Input.mousePosition); // this ray will hit some colliders RaycastHit[] _hits = Physics.RaycastAll(_ray); #region left button click if (Input.GetMouseButtonDown(0)) { for (int i = 0; i < _hits.Length; i++) { string _group = _hits[i].collider.tag; int _layer = _hits[i].collider.gameObject.layer; // click a shop if (_group.Equals("shop")) { leftMouseClkGo = _hits[i].collider.gameObject; // open shop UI there break; } // only hero and dogface can be affected by a skill // user can not click on character and shop at the same time if ((_layer == 8 || _layer == 9) && (_group == "red" || _group == "blue")) { leftMouseClkGo = _hits[i].collider.gameObject; break; } // close all dynamic UI when click on terrain if (_group == "terrain") { // close UI there continue; } } } #endregion #region right button click else if (Input.GetMouseButtonDown(1)) { int i = 0; for (i = 0; i < _hits.Length; i++) { string _group = _hits[i].collider.tag; // right click on terrain if (_group == "terrain") { targetPosition = _hits[i].point; rightMouseClkGo = _hits[i].collider.gameObject; SetCursor(GameCode.CursorCode.Normal); continue; } // right click on a enemy if (AtDifferentGroup(_group, gameObject.tag)) { BaseController _ctrl = _hits[i].collider.gameObject.GetComponent <BaseController>(); if (_ctrl == null || _ctrl.hasDead) { continue; } // click effect GameObject _clk = PoolManager.GetInstance().GetPool(clickRed.name, clickRed).GetObject(_hits[i].point); targetPosition = _hits[i].collider.transform.position; rightMouseClkGo = _hits[i].collider.gameObject; targetSize = _hits[i].collider.bounds.size; stopDis = (targetSize.x + targetSize.z) / 3.0f + m_property.atkRange; if (Vector3.Distance(rightMouseClkGo.transform.position, transform.position) > stopDis) { m_agent.SetDestination(rightMouseClkGo.transform.position); m_animator.SetBool("fight", true); transform.LookAt(rightMouseClkGo.transform); target = rightMouseClkGo; } else if (!m_animator.GetCurrentAnimatorStateInfo(0).IsTag("a")) { m_agent.Stop(); if (Random.value < m_property.critRate) { m_animator.SetBool("atk1", false); m_animator.SetBool("crit", true); } else { m_animator.SetBool("atk1", true); m_animator.SetBool("crit", false); } transform.LookAt(rightMouseClkGo.transform); m_agent.stoppingDistance = stopDis; } return; } } if (rightMouseClkGo.tag == "terrain") { // click effect Vector3 _pos = new Vector3(targetPosition.x, targetPosition.y + 1, targetPosition.z); GameObject _clk = PoolManager.GetInstance().GetPool(clickGreen.name, clickGreen).GetObject(_pos); m_agent.SetDestination(targetPosition); m_animator.SetBool("haspath", m_agent.hasPath); m_animator.SetBool("stopfight", true); m_animator.SetBool("fight", false); StopAttack(); } } #endregion return; }
// Update is called once per frame void Update() { //レイヤー番号をここに入れる animStateInfo = animator.GetCurrentAnimatorStateInfo(0); //attack_Flgがtrueの時にだけ攻撃する if (attack_Flg == true) { attack_Flg = false; //攻撃の種類を決める attack_Type = Random.Range(1, 5); //噛みつき攻撃 if (attack_Type == 1) { Bite_Attack(); } } //ブレスの攻撃 if (attack_Type == 2) { breath_Attack_Flg = true; //ここを変える if (idou_flg == true && transform.position.z <= 6) { float step = speed * Time.deltaTime; transform.position = Vector3.MoveTowards(transform.position, endMarker, step); } //ブレスのために後ろに下がる処理 if (transform.position.z == 6 && breath_Flg == true) { idou_flg = false; breath_Flg = false; animator.SetTrigger("Fly Fire Breath Attack"); Ciled = transform.Find("RigHeadGizmo/FX-Fire Breath"); Ciled.gameObject.GetComponent <ParticleSystem>().Play(); audioSource.PlayOneShot(DragonVoice3); //ブレスの瞬間に-5HP減る処理 PHP.gameObject.GetComponent <HPbar>().Set_HP(); } //ブレスを吐き終わる処理 if (breath_Flg == false && breath_time == true) { Breath_tmpTime += Time.deltaTime; if (Breath_tmpTime >= Breath_interval) { breath_time = false; animator.SetTrigger("Fly Fire Breath Attack"); Ciled = transform.Find("RigHeadGizmo/FX-Fire Breath"); Ciled.gameObject.GetComponent <ParticleSystem>().Stop(); idou_flg2 = true; } } //ここも変える //ブレスが終わって前に戻ってくる処理 if (idou_flg2 == true && transform.position.z >= 4) { float step = speed * Time.deltaTime; transform.position = Vector3.MoveTowards(transform.position, endMarker2, step); if (transform.position.z == 4) { idou_flg2 = false; breath_Attack_Flg = false; attack_Type = 999; } } } //魔法攻撃(爆発) if (attack_Type == 3) { breath_Attack_Flg = true; magicAttack_flg = true; animator.SetTrigger("MagicAttack"); MagicEffect.gameObject.GetComponent <ParticleSystem>().Play(); attack_Type = 999; } if (animStateInfo.fullPathHash == Animator.StringToHash("Base Layer.MagicAttack")) { //アニメーションの終了を感知 if (animStateInfo.normalizedTime >= 0.8f) { MagicEffect.gameObject.GetComponent <ParticleSystem>().Stop(); if (playerEffect_flg == true) { playerEffect_flg = false; PlayerEffect.GetComponent <PlayerEffect>().Play_Effect(); //爆発HP減る処理 PHP.gameObject.GetComponent <HPbar>().Set_HP2(150); } breath_Attack_Flg = false; } } //魔法攻撃(氷) if (attack_Type == 4) { //一回だけこの中を通る if (IceMagicAttack_tmpTime == 0) { breath_Attack_Flg = true; GameObject iceManager = GameObject.Find("IceManager"); iceManager.GetComponent <IceManager>().iceMagicAttack_falg = true; } IceMagicAttack_tmpTime += Time.deltaTime; if (IceMagicAttack_tmpTime > IceMagicAttack_interval) { attack_Type = 999; breath_Attack_Flg = false; IceMagicAttack_tmpTime = 0; } } if (breath_Attack_Flg == false) { //秒数をカウントしていく tmpTime += Time.deltaTime; } //n秒間隔で攻撃 if (tmpTime >= Attack_interval) { tmpTime = 0; attack_Flg = true; //ここでいろんなフラグを元に戻している Breath_tmpTime = 0; breath_Flg = true; idou_flg = true; idou_flg2 = false; breath_time = true; playerEffect_flg = true; magicAttack_flg = false; magicAttackCancel = 50; animator.SetInteger("Magicattack", 0); } }
void MoveChan(float h, float v) { if (used_spec) { ChangeAnimationState(_animation_states.Idle.ToString()); used_spec = false; } anim.SetFloat("Speed", v); // Animator側で設定している"Speed"パラメタにvを渡す anim.SetFloat("Direction", h); // Animator側で設定している"Direction"パラメタにhを渡す anim.speed = animSpeed; // Animatorのモーション再生速度に animSpeedを設定する currentBaseState = anim.GetCurrentAnimatorStateInfo(0); // 参照用のステート変数にBase Layer (0)の現在のステートを設定する rb.useGravity = true; //ジャンプ中に重力を切るので、それ以外は重力の影響を受けるようにする // 以下、キャラクターの移動処理 velocity = new Vector3(0, 0, v); // 上下のキー入力からZ軸方向の移動量を取得 // キャラクターのローカル空間での方向に変換 velocity = transform.TransformDirection(velocity); //以下のvの閾値は、Mecanim側のトランジションと一緒に調整する if (v > 0.1) { velocity *= forwardSpeed; // 移動速度を掛ける } else if (v < -0.1) { velocity *= backwardSpeed; // 移動速度を掛ける } if (Input.GetButtonDown("Jump")) { // スペースキーを入力したら //アニメーションのステートがLocomotionの最中のみジャンプできる if (currentBaseState.nameHash == locoState) { //ステート遷移中でなかったらジャンプできる if (!anim.IsInTransition(0)) { rb.AddForce(Vector3.up * jumpPower, ForceMode.VelocityChange); anim.SetBool("Jump", true); // Animatorにジャンプに切り替えるフラグを送る } } } // 上下のキー入力でキャラクターを移動させる transform.localPosition += velocity * Time.fixedDeltaTime; // 左右のキー入力でキャラクタをY軸で旋回させる transform.Rotate(0, h * rotateSpeed, 0); // 以下、Animatorの各ステート中での処理 // Locomotion中 // 現在のベースレイヤーがlocoStateの時 if (currentBaseState.nameHash == locoState) { //カーブでコライダ調整をしている時は、念のためにリセットする if (useCurves) { resetCollider(); } } // JUMP中の処理 // 現在のベースレイヤーがjumpStateの時 else if (currentBaseState.nameHash == jumpState) { cameraObject.SendMessage("setCameraPositionJumpView"); // ジャンプ中のカメラに変更 // ステートがトランジション中でない場合 if (!anim.IsInTransition(0)) { // 以下、カーブ調整をする場合の処理 if (useCurves) { // 以下JUMP00アニメーションについているカーブJumpHeightとGravityControl // JumpHeight:JUMP00でのジャンプの高さ(0〜1) // GravityControl:1⇒ジャンプ中(重力無効)、0⇒重力有効 float jumpHeight = anim.GetFloat("JumpHeight"); float gravityControl = anim.GetFloat("GravityControl"); if (gravityControl > 0) { rb.useGravity = false; //ジャンプ中の重力の影響を切る } // レイキャストをキャラクターのセンターから落とす Ray ray = new Ray(transform.position + Vector3.up, -Vector3.up); RaycastHit hitInfo = new RaycastHit(); // 高さが useCurvesHeight 以上ある時のみ、コライダーの高さと中心をJUMP00アニメーションについているカーブで調整する if (Physics.Raycast(ray, out hitInfo)) { if (hitInfo.distance > useCurvesHeight) { col.height = orgColHight - jumpHeight; // 調整されたコライダーの高さ float adjCenterY = orgVectColCenter.y + jumpHeight; col.center = new Vector3(0, adjCenterY, 0); // 調整されたコライダーのセンター } else { // 閾値よりも低い時には初期値に戻す(念のため) resetCollider(); } } } // Jump bool値をリセットする(ループしないようにする) anim.SetBool("Jump", false); } } // IDLE中の処理 // 現在のベースレイヤーがidleStateの時 else if (currentBaseState.nameHash == idleState) { //カーブでコライダ調整をしている時は、念のためにリセットする if (useCurves) { resetCollider(); } // スペースキーを入力したらRest状態になる if (Input.GetButtonDown("Jump")) { anim.SetBool("Rest", true); } } // REST中の処理 // 現在のベースレイヤーがrestStateの時 else if (currentBaseState.nameHash == restState) { //cameraObject.SendMessage("setCameraPositionFrontView"); // カメラを正面に切り替える // ステートが遷移中でない場合、Rest bool値をリセットする(ループしないようにする) if (!anim.IsInTransition(0)) { anim.SetBool("Rest", false); } } }
// Fixed update is called in sync with physics private void FixedUpdate() { attribute _attr = this.gameObject.GetComponent <attribute>(); if (CoolDownTime > 0) { CoolDownTime -= Time.fixedDeltaTime; } if (Skill_1_CoolDownTime > 0) { Skill_1_CoolDownTime -= Time.fixedDeltaTime; Skill_1_Icon.GetComponent <Image>().fillAmount = Mathf.Max(0, Skill_1_CoolDownTime) / Skill_1_CoolDownTime_Max; StateIcon.transform.Find("Skill1").gameObject.GetComponent <Image>().fillAmount = Mathf.Max(1 - (Skill_1_CoolDownTime_Max - Skill_1_CoolDownTime) / Skill_1_Duration, 0.0f); if (Skill_1_CoolDownTime_Max - Skill_1_CoolDownTime >= Skill_1_Duration && Skill_1_active) { Skill_1_active = false; Renderer[] list; list = this.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); for (int i = 0; i < list.Length; i++) { list[i].materials[0].color = Color.white; } _attr.ATK_bouns -= _attr.ATK * (Skill_1_Value[0] + Skill_1_Value[3] * _attr.Skill_Level[0] - 1); //_attr.DEF_bouns -= _attr.DEF * (Skill_1_Value[1] + Skill_1_Value[4] * _attr.Skill_Level[0] - 1); //_attr.ATK /= Skill_1_Value[0] + Skill_1_Value[3] * _attr.Skill_Level[0]; //_attr.DEF /= Skill_1_Value[1] + Skill_1_Value[4] * _attr.Skill_Level[0]; this.gameObject.GetComponent <ThirdPersonCharacter>().m_MoveSpeedMultiplier /= Skill_1_Value[2] + Skill_1_Value[5] * _attr.Skill_Level[0]; } } if (Skill_2_CoolDownTime > 0) { Skill_2_CoolDownTime -= Time.fixedDeltaTime; Skill_2_Icon.GetComponent <Image>().fillAmount = Mathf.Max(0, Skill_2_CoolDownTime) / Skill_2_CoolDownTime_Max; StateIcon.transform.Find("Skill2").gameObject.GetComponent <Image>().fillAmount = Mathf.Max(1 - (Skill_2_CoolDownTime_Max - Skill_2_CoolDownTime) / Skill_2_Duration, 0.0f); if (Skill_2_active) { this.gameObject.GetComponent <attribute>().update_HP((Skill_2_Value[1] + Skill_2_Value[3] * this.gameObject.GetComponent <attribute>().Skill_Level[1]) * Time.fixedDeltaTime); } if (Skill_2_CoolDownTime_Max - Skill_2_CoolDownTime >= Skill_2_Duration && Skill_2_active) { Skill_2_active = false; } } if (Skill_3_CoolDownTime > 0) { Skill_3_CoolDownTime -= Time.fixedDeltaTime; Skill_3_Icon.GetComponent <Image>().fillAmount = Mathf.Max(0, Skill_3_CoolDownTime) / Skill_3_CoolDownTime_Max; StateIcon.transform.Find("Skill3").gameObject.GetComponent <Image>().fillAmount = Mathf.Max(1 - (Skill_3_CoolDownTime_Max - Skill_3_CoolDownTime) / (Skill_3_Value[0] + Skill_3_Value[1] * _attr.Skill_Level[2]), 0.0f); if (Skill_3_CoolDownTime_Max - Skill_3_CoolDownTime >= Skill_3_Value[0] + Skill_3_Value[1] * _attr.Skill_Level[2] && Skill_3_active) { Skill_3_active = false; this.gameObject.transform.Find("Skill_3_shelter").gameObject.SetActive(false); Sa.DamagePerSecond = Safe_area_damage_persecond_record; _attr.DEF_bouns -= _attr.DEF * (Skill_1_Value[1] + Skill_1_Value[4] * _attr.Skill_Level[2] - 1); } } if (Skill_4_CoolDownTime > 0) { Skill_4_CoolDownTime -= Time.fixedDeltaTime; Skill_4_Icon.GetComponent <Image>().fillAmount = Mathf.Max(0, Skill_4_CoolDownTime) / Skill_4_CoolDownTime_Max; } if (ATKTime > 0) { ATKTime -= Time.fixedDeltaTime; StateIcon.transform.Find("ATK").gameObject.GetComponent <Image>().fillAmount = Mathf.Max(ATKTime / ATKTime_max, 0.0f); if (ATKTime <= 0) { _attr.ATK_bouns -= _attr.ATK * (ATK_multiplier - 1); } } if (DEFTime > 0) { DEFTime -= Time.fixedDeltaTime; StateIcon.transform.Find("DEF").gameObject.GetComponent <Image>().fillAmount = Mathf.Max(DEFTime / DEFTime_max, 0.0f); if (DEFTime <= 0) { _attr.DEF_bouns -= _attr.DEF * (DEF_multiplier - 1); } } if (item_cooldown > 0) { item_cooldown -= Time.fixedDeltaTime; } if (!(this.gameObject.GetComponent <attribute>().ifAlive)) { return; } // read inputs float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); if (v < 0) { v = 0; } m_Move = 3f * v * this.transform.forward + 1f * h * this.transform.right; int state_now = m_Animator.GetCurrentAnimatorStateInfo(0).shortNameHash; if (state_now == Animator.StringToHash("Grounded") && Input.GetKeyDown(KeyCode.J) && CoolDownTime <= 0) //If use mouse, change to Input.GetButtonDown("Fire1") { CoolDownTime = _attri.FireRate; m_Animator.SetFloat("Random", UnityEngine.Random.Range(0f, 1f)); m_Animator.SetTrigger("attack"); GameObject temp = Instantiate(attack_object, attaction_generate_position.position, attaction_generate_position.rotation); temp.GetComponent <ballistic>().speed = _attri.BallisticSpeed; temp.GetComponent <ballistic>().side = _attri.team; temp.GetComponent <ballistic>().damage = _attri.ATK + _attri.ATK_bouns + UnityEngine.Random.Range(-3, 3); temp.GetComponent <ballistic>().From = this.gameObject; temp.GetComponent <ballistic>().duration = this.gameObject.GetComponent <attribute>().ZhiYe == "warrior" ? 1.0f : 3.0f; temp.GetComponent <Rigidbody>().velocity = (attaction_generate_position.forward).normalized * _attri.BallisticSpeed; temp.tag = "Team0"; } if (state_now == Animator.StringToHash("Grounded") && Input.GetKeyDown(KeyCode.U) && Skill_1_CoolDownTime <= 0 && _attr.Skill_Level[0] > 0) { Skill_1_active = true; Skill_1_CoolDownTime = Skill_1_CoolDownTime_Max; Renderer[] list; list = this.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); for (int i = 0; i < list.Length; i++) { list[i].materials[0].color = Color.red; } _attr.ATK_bouns += _attr.ATK * (Skill_1_Value[0] + Skill_1_Value[3] * _attr.Skill_Level[0] - 1); //_attr.DEF_bouns += _attr.DEF * (Skill_1_Value[1] + Skill_1_Value[4] * _attr.Skill_Level[0] - 1); //_attr.ATK *= Skill_1_Value[0] + Skill_1_Value[3] * _attr.Skill_Level[0]; //_attr.DEF *= Skill_1_Value[1] + Skill_1_Value[4] * _attr.Skill_Level[0]; this.gameObject.GetComponent <ThirdPersonCharacter>().m_MoveSpeedMultiplier *= Skill_1_Value[2] + Skill_1_Value[5] * _attr.Skill_Level[0]; } if (state_now == Animator.StringToHash("Grounded") && Input.GetKeyDown(KeyCode.I) && Skill_2_CoolDownTime <= 0 && _attr.Skill_Level[1] > 0) { Skill_2_active = true; Skill_2_CoolDownTime = Skill_2_CoolDownTime_Max; ParticalHPUp.SetActive(true); _attr.update_HP(Skill_2_Value[0] + Skill_1_Value[2] * _attr.Skill_Level[1]); } if (state_now == Animator.StringToHash("Grounded") && Input.GetKeyDown(KeyCode.O) && Skill_3_CoolDownTime <= 0 && _attr.Skill_Level[2] > 0) { Skill_3_active = true; Skill_3_CoolDownTime = Skill_3_CoolDownTime_Max; this.gameObject.transform.Find("Skill_3_shelter").gameObject.SetActive(true); Safe_area_damage_persecond_record = Sa.DamagePerSecond; Sa.DamagePerSecond = 0; _attr.DEF_bouns += _attr.DEF * (Skill_1_Value[1] + Skill_1_Value[4] * _attr.Skill_Level[2] - 1); } if (state_now == Animator.StringToHash("Grounded") && Input.GetKeyDown(KeyCode.P) && Skill_4_CoolDownTime <= 0 && _attr.Skill_Level[3] > 0) { Skill_4_active = true; Skill_4_CoolDownTime = Skill_4_CoolDownTime_Max; ParticleSystem.MainModule _m = this.gameObject.transform.Find("Skill_4 Partical").gameObject.GetComponent <ParticleSystem>().main; ParticleSystem.EmissionModule _e = this.gameObject.transform.Find("Skill_4 Partical").gameObject.GetComponent <ParticleSystem>().emission; _m.duration = 0.5f * (Skill_4_Value[2] + Skill_4_Value[5] * _attr.Skill_Level[3]); _e.rateOverTime = (Skill_4_Value[1] + Skill_4_Value[4] * _attr.Skill_Level[3]); this.gameObject.transform.Find("Skill_4 Partical").gameObject.SetActive(true); } if (Input.GetKeyDown(KeyCode.E) && item_cooldown < 0) { item_cooldown = 0.5f; if (ShopObject.activeInHierarchy) { ShopObject.SetActive(false); } else { ShopObject.SetActive(true); ShopObject.GetComponent <bagManager>().RefreshBag(); } } if (Input.GetKeyDown(KeyCode.F) && item_cooldown < 0) { if (MainScreenItem.transform.Find("Icon").gameObject.GetComponent <RawImage>().texture.Equals(Bag.nan) == false) { float _percentage = 0.0f; item_cooldown = 0.5f; int _x = Bag._x; int _y = Bag._y; if (_x == 0) { _percentage = _y == 0 ? 0.2f : _y == 1 ? 0.4f : _y == 2 ? 0.6f : 1.0f; _attr.update_HP(_attr.HP_max * _percentage); _attr.gameObject.transform.Find("HPup").gameObject.SetActive(true); Bag.ItemOwned[4 * _x + _y]--; Bag.RefreshBag(); MainScreenItem.transform.Find("Number").gameObject.GetComponent <Text>().text = Bag.ItemOwned[4 * _x + _y].ToString(); if (Bag.ItemOwned[4 * _x + _y] == 0) { MainScreenItem.transform.Find("Icon").gameObject.GetComponent <RawImage>().texture = Bag.nan; Bag.ItemGameObject[4 * _x + _y].transform.Find("Choosen").gameObject.SetActive(false); } } if (_x == 1) { _percentage = _y == 0 ? 0.3f : _y == 1 ? 0.6f : _y == 2 ? 0.9f : 1.5f; if (ATKTime < 0) { ATKTime = ATKTime_max; ATK_multiplier = 1 + _percentage; _attr.ATK_bouns += _attr.ATK * _percentage; //_attr.ATK *= 1 + _percentage; } else { if (1 + _percentage == ATK_multiplier) { ATKTime = ATKTime_max; } else { ATKTime = ATKTime_max; _attr.ATK_bouns -= _attr.ATK * (ATK_multiplier - 1); //_attr.ATK /= ATK_multiplier; ATK_multiplier = 1 + _percentage; _attr.ATK_bouns += _attr.ATK * _percentage; //_attr.ATK *= 1 + _percentage; } } Bag.ItemOwned[4 * _x + _y]--; Bag.RefreshBag(); MainScreenItem.transform.Find("Number").gameObject.GetComponent <Text>().text = Bag.ItemOwned[4 * _x + _y].ToString(); if (Bag.ItemOwned[4 * _x + _y] == 0) { MainScreenItem.transform.Find("Icon").gameObject.GetComponent <RawImage>().texture = Bag.nan; Bag.ItemGameObject[4 * _x + _y].transform.Find("Choosen").gameObject.SetActive(false); } } if (_x == 2) { _percentage = _y == 0 ? 0.3f : _y == 1 ? 0.6f : _y == 2 ? 0.9f : 1.5f; if (DEFTime < 0) { DEFTime = DEFTime_max; DEF_multiplier = 1 + _percentage; _attr.DEF_bouns += _attr.DEF * _percentage; //_attr.DEF *= 1 + _percentage; } else { if (1 + _percentage == DEF_multiplier) { DEFTime = DEFTime_max; } else { DEFTime = DEFTime_max; //_attr.DEF /= DEF_multiplier; _attr.DEF_bouns -= _attr.DEF * (DEF_multiplier - 1); DEF_multiplier = 1 + _percentage; //_attr.DEF *= 1 + _percentage; _attr.DEF_bouns += _attr.DEF * _percentage; } } Bag.ItemOwned[4 * _x + _y]--; Bag.RefreshBag(); MainScreenItem.transform.Find("Number").gameObject.GetComponent <Text>().text = Bag.ItemOwned[4 * _x + _y].ToString(); if (Bag.ItemOwned[4 * _x + _y] == 0) { MainScreenItem.transform.Find("Icon").gameObject.GetComponent <RawImage>().texture = Bag.nan; Bag.ItemGameObject[4 * _x + _y].transform.Find("Choosen").gameObject.SetActive(false); } } } } // pass all parameters to the character control script m_Character.Move(m_Move, false, m_Jump); m_Jump = false; }
/// <summary> /// 是否在播某个动画 /// </summary> /// <param name="animator"></param> /// <param name="clipName"></param> /// <param name="layerIndex"></param> /// <returns></returns> public static bool IsPlayAnimation(this Animator animator, string animationName, int layerIndex = 0) { AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(layerIndex); return(stateInfo.IsName(animationName)); }
void Update() { if (companionbody.velocity.x == 0 && companionbody.velocity.y == 0 && !NarrationManager.instance.isPlaying && !anim.GetCurrentAnimatorStateInfo(0).IsName("giveLife")) { CompAnimationState = 0; //idle anim } if ((companionbody.velocity.x > 0 || companionbody.velocity.x < 0) && CharScript.PlayerState != 3 && !anim.GetCurrentAnimatorStateInfo(0).IsName("giveLife")) { CompAnimationState = 1; //walk anim } if (companionstate == 1) { MoveNearPlayer(); if (this.gameObject.transform.position.y < Player.transform.position.y - 1f && jumps == 1) { StartCoroutine(Jump()); } if (jumps == 0) { MoveToPlayer(); } if (this.gameObject.transform.position.y > Player.transform.position.y + 5) { MoveToPlayer(); } if (this.gameObject.transform.position.y > Player.transform.position.y + 7 || this.gameObject.transform.position.y < Player.transform.position.y - 7) { this.gameObject.transform.position = Player.transform.position; } if (this.gameObject.transform.position.x > Player.transform.position.x + 10 || this.gameObject.transform.position.x < Player.transform.position.x - 10) { this.gameObject.transform.position = Player.transform.position; } } comphealthbar.GetComponent <RectTransform>().transform.localScale = new Vector3(comphealth / 37.5f, 0.1f, 1); comphealthbar.transform.position = new Vector2(this.gameObject.transform.position.x - 1, this.gameObject.transform.position.y + 1.5f); visualCompHealthBar.transform.position = new Vector2(this.gameObject.transform.position.x - 1.2f, this.gameObject.transform.position.y + 1.5f); if (comphealth > 100) { comphealth = 100; } if (comphealth <= 0) { comphealth = 0.000001f; //(if set as 0, this if case will keep looping) companionbody.velocity = new Vector2(0, companionbody.velocity.y / speed) * speed; companionstate = 0; CharScript.sanity = 0; CharScript.PlayerAnimationState = 6; CompAnimationState = 3; //dead anim } if (companionbody.velocity.x > 0) { transform.localScale = new Vector2(CompScale, transform.localScale.y); } else if (companionbody.velocity.x < 0) { transform.localScale = new Vector2(-CompScale, transform.localScale.y); } SetAnimationState(); }
/// <summary> /// Get and update animator parameters at end of each frame. /// </summary> private void LateUpdate() { InAttkComboAndCanMove = anim.GetCurrentAnimatorStateInfo(0).IsTag("CanMoveAttack"); DoingAttack = anim.GetCurrentAnimatorStateInfo(0).IsTag("Attack") || InAttkComboAndCanMove; AnimMoveSpeedPenalty = anim.GetFloat("MoveSpeedPenaltyPercentage"); }
// Use this for initialization void Start() { animator = GetComponent<Animator>(); combatStateInfo = animator.GetCurrentAnimatorStateInfo(1); baseStateInfo = animator.GetCurrentAnimatorStateInfo(0); }