void Update() { // All players on network have the same prefab, so there needs to be a way to choose the local one // If not the local player, then don't take in any inputs if (photonView.isMine == false && PhotonNetwork.connected == true) { return; } // Only jump when running AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0); // Run is in Base Layer, ask for current state if (stateInfo.IsName("Base Layer.Run")) { if (Input.GetButtonDown("Fire2")) { animator.SetTrigger("Jump"); } } if (!animator) { return; } // Read user input float horiz = Input.GetAxis("Horizontal"); float vert = Input.GetAxis("Vertical"); // No backwards movement if (vert < 0) { vert = 0; } animator.SetFloat("Speed", vert * vert); animator.SetFloat("Direction", horiz, DirectionDampTime, Time.deltaTime); }
private void Update() { if (train.activeSelf) { AnimatorStateInfo asi = animator.GetCurrentAnimatorStateInfo(0); if ((asi.normalizedTime > 1.0f) && (asi.IsName(animationName))) { Lucky.LuckyUtils.Log("train arrive"); train.SetActive(false); string city = FindPlaceName(dst); UserTicketsModel.Instance.where = Where.City; UserTicketsModel.Instance.city = city; BuyTicketsModel.Instance.startlocation = city; BuyTicketsModel.Instance.stoplocation = "沈阳"; TimeManager.instance.SetNormalSpeed(); EventHappenManager.Instance.EveryLocation(city); UserTicketsModel.Instance.going = false; } } if (airplane.activeSelf) { AnimatorStateInfo asi = animator.GetCurrentAnimatorStateInfo(0); if ((asi.normalizedTime > 1.0f) && (asi.IsName(animationName))) { Lucky.LuckyUtils.Log("airplane arrive"); airplane.SetActive(false); UserTicketsModel.Instance.where = Where.City; string city = FindPlaceName(dst); UserTicketsModel.Instance.city = city; BuyTicketsModel.Instance.startlocation = city; BuyTicketsModel.Instance.stoplocation = "沈阳"; TimeManager.instance.SetNormalSpeed(); airline.gameObject.SetActive(false); EventHappenManager.Instance.EveryLocation(city); UserTicketsModel.Instance.going = false; } } }
public roleState getRoleNowState() { roleState resState = roleState.init; //需把所有状态遍历一遍才可知 if (animator == null) { return(resState); } AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0); if (info.normalizedTime >= 1.0f) { resState = roleState.init; } else { if (info.IsName(strStand)) { resState = roleState.stand; } else if (info.IsName(strRun)) { resState = roleState.run; } else if (info.IsName(strAttack)) { resState = roleState.attack; } else if (info.IsName(strAttack2)) { resState = roleState.attack2; } else if (info.IsName(strDef)) { resState = roleState.def; } else if (info.IsName(strDie)) { resState = roleState.die; } } return(resState); }
// Update is called once per frame void Update() { state = anim.GetCurrentAnimatorStateInfo(0); if (state.IsName("Del")) { if (type == 0) { GameObject aCard = Instantiate(asteroids, gameObject.GetComponent <Transform> ().position, gameObject.GetComponent <Transform> ().rotation) as GameObject; aCard.GetComponent <ActiveCard> ().TT = TT; } if (type == 1) { GameObject aCard = Instantiate(bandits, gameObject.GetComponent <Transform> ().position, gameObject.GetComponent <Transform> ().rotation) as GameObject; aCard.GetComponent <ActiveCard> ().TT = TT; } if (type == 2) { GameObject aCard = Instantiate(trader, gameObject.GetComponent <Transform> ().position, gameObject.GetComponent <Transform> ().rotation) as GameObject; aCard.GetComponent <ActiveCard> ().TT = TT; } if (type == 3) { GameObject aCard = Instantiate(exit, gameObject.GetComponent <Transform> ().position, gameObject.GetComponent <Transform> ().rotation) as GameObject; aCard.GetComponent <ActiveCard> ().TT = TT; } if (type == 4) { GameObject aCard = Instantiate(drydock, gameObject.GetComponent <Transform> ().position, gameObject.GetComponent <Transform> ().rotation) as GameObject; aCard.GetComponent <ActiveCard> ().TT = TT; } if (type == 5) { GameObject aCard = Instantiate(nebula, gameObject.GetComponent <Transform> ().position, gameObject.GetComponent <Transform> ().rotation) as GameObject; aCard.GetComponent <ActiveCard> ().TT = TT; } Destroy(gameObject); } }
public override void Act(UnityEngine.Transform player, UnityEngine.Transform npc) { AnimatorStateInfo stateinfo = animator.GetCurrentAnimatorStateInfo(0); if (!stateinfo.IsName(info.name)) { animator.SetInteger("State", info.id); } for (int index = 0; index < dragonController.Renderer.Length; ++index) { float value = dragonController.Renderer[index].material.GetFloat("_Cutoff"); value += Time.fixedDeltaTime; value = value > 1 ? 1 : value; dragonController.Renderer[index].material.SetFloat("_Cutoff", value); bool hasDesappear = value == 1 ? true : false; if (hasDesappear) { dragonController.DeSpawn(); } } }
private void OnDown(PointerEventData data) { //Debug.LogError("OnDown 1 "+ _drawCardAnimationEvent.CurDrawCardState); switch (_drawCardAnimationEvent.CurDrawCardState) { case DrawCardAnimationEvent.CURANIMALSTATE.NONE: break; case DrawCardAnimationEvent.CURANIMALSTATE.PRESS: _pressDownTime = Time.time; _drawCardA.SetBool("IsPress", true); AudioManager.Instance.PlayEffect("draw_star", 1); break; case DrawCardAnimationEvent.CURANIMALSTATE.RESULATING: break; case DrawCardAnimationEvent.CURANIMALSTATE.RESULATED: //can change to repeating state ShowAwardCard(); break; case DrawCardAnimationEvent.CURANIMALSTATE.REPEATING: break; case DrawCardAnimationEvent.CURANIMALSTATE.REPEATED: //can change to next repeate state AnimatorStateInfo stateInfo = _drawCardA.GetCurrentAnimatorStateInfo(0); if (stateInfo.IsName("Base Layer.RepeatResult")) //状态快速切换 一帧内多次切换一些状态 bug解决方法 { // Debug.LogError("Base Layer.RepeatResult"); return; } // Debug.LogError("OnDown 2" + _drawCardAnimationEvent.CurDrawCardState); ShowAwardCard(); break; } }
protected void WasHitFly() { AnimatorStateInfo state = animator.GetCurrentAnimatorStateInfo(0); if (state.IsName("BaseLayer.StandUp")) { if (state.normalizedTime > 0.9f) { currentMotionState = MotionState.Idling; animator.SetBool("HitFly", false); } } if (currentMotionState == MotionState.HitFly) { animator.SetBool("HitFly", true); currentMotionState = MotionState.StandingUp; transform.LookAt(wasHitFlyInfo.Position); Vector3 direction = transform.position - wasHitFlyInfo.Position; direction.Normalize(); rigidBody.AddForce(wasHitFlyInfo.Distance * direction, ForceMode.VelocityChange); } }
// Update is called once per frame void Update() { AnimatorStateInfo stateinfo = animator.GetCurrentAnimatorStateInfo(0);//获取当前动作 if ((Input.GetKey(KeyCode.W)) || (Input.GetKey(KeyCode.S)) || (Input.GetKey(KeyCode.A)) || (Input.GetKey(KeyCode.D))) { if (!stateinfo.IsName("Attack"))//如果不在攻击,则可以移动,否则禁止移动 { if (Input.GetKey(KeyCode.W)) { //根据主相机的朝向决定人物的移动方向,下同 controller.transform.eulerAngles = new Vector3(0, m_camera.transform.eulerAngles.y, 0); } else if (Input.GetKey(KeyCode.S)) { controller.transform.eulerAngles = new Vector3(0, m_camera.transform.eulerAngles.y + 180f, 0); } else if (Input.GetKey(KeyCode.A)) { controller.transform.eulerAngles = new Vector3(0, m_camera.transform.eulerAngles.y + 270f, 0); } else if (Input.GetKey(KeyCode.D)) { controller.transform.eulerAngles = new Vector3(0, m_camera.transform.eulerAngles.y + 90f, 0); } controller.Move(m_transform.forward * Time.deltaTime * MoveSpeed); } } if (!controller.isGrounded) { //模拟简单重力,每秒下降10米,当然你也可以写成抛物线 controller.Move(new Vector3(0, -10f * Time.deltaTime, 0)); } }
public void BtnClick() { GameObject gameObject = GameObject.Find("girl_02"); Animator componentInChildren = gameObject.GetComponentInChildren <Animator>(); if (componentInChildren) { } this.mAnimIndex++; AnimatorStateInfo currentAnimatorStateInfo = componentInChildren.GetCurrentAnimatorStateInfo(0); componentInChildren.CrossFade("run", 0.2f); componentInChildren.CrossFade("attcked", 0.2f); if (currentAnimatorStateInfo.IsName("warwait")) { componentInChildren.speed = 2f; } else { componentInChildren.speed = 1f; } }
// Update is called once per frame void Update() { float v = Input.GetAxis("Vertical"); float h = Input.GetAxis("Horizontal"); GroundMovement(h, v); VerticalMovement(); moveVector *= Time.deltaTime; _controller.Move(moveVector); moveVector.y = 0; AnimatorStateInfo stateInfo = _animator.GetCurrentAnimatorStateInfo(0); if (!stateInfo.IsName("Base Layer.Attack")) { transform.LookAt(transform.position + moveVector); } Crouch(); SetAnimatorParameters(h, v); if (_healthScript.health < previousHealth) { if (_healthScript.health <= 0) { canControl = false; _animator.SetTrigger("die"); this.enabled = false; } else { _animator.SetTrigger("hurt"); } } previousHealth = _healthScript.health; }
private void DoBlastWave() { AnimatorStateInfo info = _anim.GetCurrentAnimatorStateInfo(0); if (info.IsName("zuibu_fachuchongjibo") && info.normalizedTime >= 1) { switch (_curWalkType) { case WALK_TYPE.GRAOUND: SetState(FS_STATE.IDLE); break; case WALK_TYPE.WALL: SetState(FS_STATE.IDLE_WALL); break; case WALK_TYPE.ROOF: SetState(FS_STATE.WALK_ROOF); break; } } }
private void DoCannon() { AnimatorStateInfo info = _anim.GetCurrentAnimatorStateInfo(0); if (info.IsName("kaipao") && info.normalizedTime >= 1) { switch (_curWalkType) { case WALK_TYPE.GRAOUND: SetState(FS_STATE.IDLE); break; case WALK_TYPE.WALL: SetState(FS_STATE.IDLE_WALL); break; case WALK_TYPE.ROOF: SetState(FS_STATE.WALK_ROOF); break; } } }
public override void Act(UnityEngine.Transform player, UnityEngine.Transform npc) { dragonController.StateChange = false; AnimatorStateInfo stateinfo0 = animator.GetCurrentAnimatorStateInfo(0); if (!stateinfo0.IsName(info.name)) { animator.SetInteger("State", info.id); } AnimatorStateInfo stateinfo1 = animator.GetCurrentAnimatorStateInfo(0); if (stateinfo1.IsName(info.name) && stateinfo1.normalizedTime >= 0.99f) { dragonController.StateChange = true; // 相机震动 ioo.cameraManager.NormalShake(); // 爆炸音效 ioo.audioManager.PlaySound2D(dragonController.ExplodeEffectSound); //EventDispatcher.TriggerEvent(EventDefine.Event_Player_Damage, dragonController.AttackDamage); } }
// Update is called once per frame void Update() { AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0); if (stateInfo.IsName("run")) { anim.SetBool("ColliderTouched", false); timeRuning -= Time.deltaTime; if (world.doUpdate) { Vector3 temp = transform.position; temp.x += 0.1f + slowFPSmoveX; transform.position = temp; slowFPSmoveX = 0.0f; } else { slowFPSmoveX += 0.1f; } anim.SetFloat("TimeRuning", timeRuning); } }
void AtaqueHacha() { // Buscamos el estado actual mirando la información del animador AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0); bool attacking = stateInfo.IsName("Player_Attack_Hacha"); if (Input.GetButtonDown("attack") && !attacking) { anim.SetTrigger("attacking"); } if (mov != Vector2.zero) { attackCollider.offset = new Vector2(mov.x / 2, mov.y / 2); } // Activamos el collider a la mitad de la animación de ataque if (attacking) { // El normalized siempre resulta ser un ciclo entre 0 y 1 float playbackTime = stateInfo.normalizedTime; if (playbackTime > 0.33 && playbackTime < 0.66) { attackCollider.enabled = true; } else { attackCollider.enabled = false; } //Actualizar estado a atacando currentState = PlayerState.attack; } if (currentState != PlayerState.interact) { currentState = PlayerState.walk; } }
void Attack() { //reubicación collider attack (según posición de player) if (move != Vector2.zero) //si se mueve, modifica posición collider { _attackCollider.offset = new Vector2(move.x / 2, move.y / 2); } AnimatorStateInfo info = playerAnimator.GetCurrentAnimatorStateInfo(0); bool _animAttacking = info.IsName("Player_Attack"); //si no está atacando, ataca (se asegura que termine la animación antes de empezar nueva) if (Input.GetKeyDown(KeyCode.Space) && !_animAttacking) { playerAnimator.SetTrigger("attacking"); _attackCollider.enabled = true; //activa espada } else if (!_animAttacking) { _attackCollider.enabled = false; //desactiva espada } }
void FixedUpdate() { if (pm != null) { if (isDestroy) { transform.Translate(Vector3.up * 20 * Time.deltaTime); } else { if (cs.mCurMobalId == MobaObjectID.HeroJiansheng) { //cs.attackTarget = CharacterManager.instance.GetAttackTarget(3f); if (cs.attackTarget == null || cs.attackTarget.tag == Tag.tower) { DestoryMe(); } } else if (cs.mCurMobalId == MobaObjectID.HeroHuonv && target != null) { if (cs.emission.et != null && cs.emission.et is EffectAOECenter) { //{ ((EffectAOECenter)cs.emission.et).mForceForward = target.transform.position - transform.position; } //} //transform.LookAt(target.transform); } } AnimatorStateInfo mStateInfo = pm.ani.GetCurrentAnimatorStateInfo(0); if ((mStateInfo.IsName("Skill4") && mStateInfo.normalizedTime >= 0.95f) || mStateInfo.IsName("Prepare")) { if (cs.emission.et == null && cs.mCurMobalId != MobaObjectID.HeroJiansheng) { DestoryMe(); } } } }
void MoveCharacter() { float currForwardSpeed = m_Animator.GetFloat(m_HashForwardSpeed); if (ic.IsRun && m_CurrentStateInfo.IsName("Moving")) { if (m_LastStateInfo.IsName("Dash")) { m_Animator.SetFloat(m_HashForwardSpeed, 0.4f); } else { m_Animator.SetFloat(m_HashForwardSpeed, Mathf.MoveTowards(currForwardSpeed, 1f, 3f * Time.fixedDeltaTime)); } } else { m_Animator.SetFloat(m_HashForwardSpeed, Mathf.Lerp(currForwardSpeed, 0f, 10f * Time.fixedDeltaTime)); } m_Animator.SetBool(m_HashIsMove, ic.IsMove); rig.velocity = Vector3.zero; }
public void FixedUpdate() { AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0); animator.SetFloat("ForwardInput", v); animator.SetInteger("RaceState", rs); animator.SetBool("BogWalk", bg); if (winded == 0) { transform.Rotate(0, h * Time.deltaTime * rotSpeed, 0); animator.SetFloat("Turning", h); } if (stateInfo.IsName("Base Layer.Idle")) { if (canJump && grounded && j == 1) { rb.AddForce(Vector3.up * 200); } ProcessJump(); } }
override protected void Attack() { if (contadorflechas > 0) { if (Controllers.GetButton(1, "A", 1)) { anim.SetBool("Attack", true); } if (Controllers.GetButton(1, "A", 2)) { animStateInfo = anim.GetCurrentAnimatorStateInfo(0); if (animStateInfo.IsName("shoot-still")) { objectPooler.GetObjectFromPool("Arrow", arrowSpawner.transform.position, arrowSpawner.transform.rotation, null); } anim.SetBool("Attack", false); contadorflechas -= 1; textArrows.text = "Flechas: " + contadorflechas; } } }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (stateInfo.IsName("TakeDamage")) { var player = GameObject.Find("Player 1"); var originalColor = player.GetComponent <SpriteRenderer>().color; D.Assert(player != null, "Can't find player object"); //var player = GameObject.Find("Player"); //D.Assert(sprite != null, "Can't find Sprite Renderer on player object"); //var startColor = sprite.color; //todo: play particle effect on damage TweenerExtension.TakeDamageEffects(player); //GameObject.Find("Player 1").GetComponent<SpriteRenderer>().color = originalColor; //GameObject.Find("PlayerHealthComponent").GetComponent<SpriteRenderer>().color = originalColor; //TweenerExtension.ShakeCam(2f,2f,1f); //TweenerExtension.BlinkColor(player, new Color(10f, 1f, 1f, 0.8f), 1f); ResetAnimationState(animator); } }
private IEnumerator CheckCrossFadeEnd(string stateName, System.Action finishCallback) { AnimatorStateInfo currentStateInfo = new AnimatorStateInfo(); while (true) { if (animator.IsInTransition(MAIN_LAYER)) { currentStateInfo = animator.GetNextAnimatorStateInfo(MAIN_LAYER); } else { currentStateInfo = animator.GetCurrentAnimatorStateInfo(MAIN_LAYER); } if (currentStateInfo.IsName(stateName) && currentStateInfo.normalizedTime >= 1f) { finishCallback(); break; } yield return(null); } }
void Update() { if (!photonView.isMine && PhotonNetwork.connected) { return; } if (!animator) { return; } // deal with Jumping AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0); // only allow jumping if we are running. if (stateInfo.IsName("Base Layer.Run")) { // When using trigger parameter if (Input.GetButtonDown("Fire2")) { animator.SetTrigger("Jump"); } } float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); if (v < 0) { v = 0; } animator.SetFloat("Speed", h * h + v * v); animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime); }
void OnAnimatorMove() { if (m_Animator.speed == 0) { return; } if (m_NavAgent.enabled) { if (NeedMove) { if (!m_Animator.GetBool("Move")) { m_Animator.SetBool("Move", true); } if (m_CrossFade) { AnimatorStateInfo stateInfo = m_Animator.GetCurrentAnimatorStateInfo(0); if (stateInfo.IsName("Base Layer.run") && !m_Animator.IsInTransition(0)) { NavmeshMove(); } } else { NavmeshMove(); } } else { if (m_Animator.GetBool("Move")) { m_NavAgent.velocity = Vector3.zero; m_Animator.SetBool("Move", false); } } } }
public override bool MatchedChangeCondition(AICharacterBrain _Brain) { animator = _Brain.GetComponent <Animator>(); animStateInfomation = animator.GetCurrentAnimatorStateInfo(0); if ((_Brain.m_SensorManager.M_GetCurrentEnemyTarget().transform.position - _Brain.m_CurrentTransform.position).sqrMagnitude > farAwayDistance * farAwayDistance) { bool _flagOfMove = true; for (int i = 0; i < matchAnimatorName.Length; i++) { if ((animStateInfomation.IsName(matchAnimatorName[i]))) { _flagOfMove = false; break; } } if (_flagOfMove) { return(true); } } return(false); }
public override void CheckCondition(MobInfo data) { AnimatorStateInfo info = data.m_AnimationController.Animator.GetCurrentAnimatorStateInfo(0); if (info.IsName("throwRock")) { if (info.normalizedTime > 0.8f) { GOBullet = ObjectPool.m_Instance.LoadGameObjectFromPool(3402); if (GOBullet == null) { return; } GOBullet.transform.position = data.m_Go.transform.position + Vector3.up; GOBullet.transform.forward = data.m_Go.transform.forward; GOBullet.transform.Rotate(new Vector3(0, 0, 0)); GOBullet.SetActive(true); data.m_FSMSystem.PerformTransition(eFSMTransition.Go_TankIdle); } return; } }
protected void OnRescued() { AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0); if (info.IsName("Rescue") && info.normalizedTime >= 1.0f) { if (this.idleTimer >= (float)dataPO.CorpseRemainTime / 1000.0f && disappearAlpha == false) { disappearAlpha = true; EventDispatcher.TriggerEvent(GameEventDef.EVNET_MONSTER_DEATH, dataPO.MonsterType, dataPO.Id); for (int index = 0; index < renderer.Length; ++index) { Tweener tw = renderer[index].material.DOFloat(1.0f, "_Cutoff", 0.5f); tw.OnComplete(OnDisappearEnd); } } else { this.idleTimer += Time.deltaTime; } } }
public override void CheckCondition(MobInfo data) { AnimatorStateInfo info = data.m_AnimationController.Animator.GetCurrentAnimatorStateInfo(0); if (info.IsName("GetHurt")) { if (info.normalizedTime > 0.9f) { if ((data.m_Player.transform.position - data.m_Go.transform.position).magnitude >= data.m_fPatrolVisionLength) { data.m_FSMSystem.PerformTransition(eFSMTransition.Go_Chase); return; } if ((data.m_Player.transform.position - data.m_Go.transform.position).magnitude < data.m_fPatrolVisionLength) { data.m_FSMSystem.PerformTransition(eFSMTransition.Go_Dodge); return; } data.m_FSMSystem.PerformTransition(eFSMTransition.Go_Flee); } } }
// void OnGUI() { if (GUI.Button(new Rect(10, 90, 300, 30), "AnimatorController")) { //舊版Animation做法: /* AnimationState anim = this.transform.animation["MainMenuButton"]; * if( anim ) * { * anim.speed = fSpeed ; * anim.wrapMode = WrapMode.Once ;//一次 * anim.time = 0; * this.transform.animation.Play("MainMenuButton"); * } */ //新版MecAnima做法 if (animator) { // 設定 物件上Animator變數,播放相對應動畫 animator.SetFloat("speed", walk); animator.SetFloat("dir", direction); } } if (GUI.Button(new Rect(10, 130, 300, 30), "IsSameAnimatorController")) { //Is Playing if (animator) { AnimatorStateInfo animatorState = animator.GetCurrentAnimatorStateInfo(0); if (animatorState.IsName("Base Layer.CarAnimation")) { //Debug.Log("动画相等"); } else { //Debug.Log("动画不等"); } } } }
/// <summary> /// 检查玩家是否死亡 /// </summary> public void CheckPlayerIsDeath() { if (player != null) { if (player.playerState == PlayerState.Death) { //player = null; StopFight(); SwitchPlayer(); } } //跳跃动画和踩踏动画时开启刚体isKinematic功能 if (bossStateInfo.IsName("trample")) { gameObject.GetComponent <Rigidbody>().isKinematic = true; } else { gameObject.GetComponent <Rigidbody>().isKinematic = false; } }