public void OnFixedUpdate(ref GruntState playerState, CGruntPhysics physics, FootMaterial footMaterial) { if (playerState == GruntState.Walking) { m_currentAnimation = "walk"; if (!m_animation.IsPlaying("walk")) { m_animation.CrossFade("walk", 0.2f); PlayFootstepAudio(footMaterial); } } else if (playerState == GruntState.Turning) { m_currentAnimation = "running-turn"; if (!m_animation.IsPlaying("running-turn") && !m_startedTurningRound) { m_startedTurningRound = true; m_animation["running-turn"].speed = 1.2f; m_animation.CrossFade("running-turn"); } else if (!m_animation.IsPlaying("running-turn")) { m_startedTurningRound = false; playerState = GruntState.Walking; } } else if (playerState == GruntState.Standing) { if (!m_animation.IsPlaying(m_lastKnownIdle)) { m_currentAnimation = "idle-" + Random.Range(0, 2); m_lastKnownIdle = m_currentAnimation; m_animation[m_currentAnimation].speed = Random.Range(10, 30) / 100.0f; m_animation.CrossFade(m_currentAnimation); } } else if (playerState == GruntState.Jumping) { m_currentAnimation = "run-jump"; if (!m_animation.IsPlaying("run-jump")) m_animation.Play("run-jump"); } else if (playerState == GruntState.FallJumping) { m_currentAnimation = "falling"; if (!m_animation.IsPlaying("falling")) m_animation.CrossFade("falling"); } else if (playerState == GruntState.FallingFromTower) { m_currentAnimation = "falling"; if (!m_animation.IsPlaying("falling")) m_animation.CrossFade("falling"); } }
/* * \brief Called when the object is created. At the start. * Only called once per instaniation. */ public override void Start() { base.Start(); if (Application.platform == RuntimePlatform.Android) { Screen.orientation = ScreenOrientation.Landscape; } //Time.timeScale = 0.75f; m_playerPositionAlpha = InitialAlphaPosition; m_name = "Grunt"; m_physics = GetComponent <CGruntPhysics>(); m_physics.Create(this, GetComponent <Rigidbody>()); //m_cameraClass = MainCamera.GetComponent<CCamera>(); m_animation = GetComponent <CGruntAnimation>(); m_animation.OnStart(GetComponentInChildren <Animation>()); m_playerHealth = MaxHealth; m_characterMesh = this.transform.Find("GruntMesh"); m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0)); m_physics.MovingDirection = StartFacing == LeftRight.Left ? 1 : -1; m_playerState = GruntState.Walking; m_dead.didDie = false; m_debug = GetComponent <CGruntDebug>(); if (m_debug != null) { m_debug.SetPlayer(this); } }
/* * \brief Called when the object is created. At the start. * Only called once per instaniation. */ public override void Start() { base.Start(); if (Application.platform == RuntimePlatform.Android) Screen.orientation = ScreenOrientation.Landscape; //Time.timeScale = 0.75f; m_playerPositionAlpha = InitialAlphaPosition; m_name = "Grunt"; m_physics = GetComponent<CGruntPhysics>(); m_physics.Create(this, GetComponent<Rigidbody>()); //m_cameraClass = MainCamera.GetComponent<CCamera>(); m_animation = GetComponent<CGruntAnimation>(); m_animation.OnStart(GetComponentInChildren<Animation>()); m_playerHealth = MaxHealth; m_characterMesh = this.transform.Find("GruntMesh"); m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0)); m_physics.MovingDirection = StartFacing == LeftRight.Left ? 1 : -1; m_playerState = GruntState.Walking; m_dead.didDie = false; m_debug = GetComponent<CGruntDebug>(); if (m_debug != null) { m_debug.SetPlayer(this); } }
public void OnFixedUpdate(ref GruntState playerState, CGruntPhysics physics, FootMaterial footMaterial) { if (playerState == GruntState.Walking) { m_currentAnimation = "walk"; if (!m_animation.IsPlaying("walk")) { m_animation.CrossFade("walk", 0.2f); PlayFootstepAudio(footMaterial); } } else if (playerState == GruntState.Turning) { m_currentAnimation = "running-turn"; if (!m_animation.IsPlaying("running-turn") && !m_startedTurningRound) { m_startedTurningRound = true; m_animation["running-turn"].speed = 1.2f; m_animation.CrossFade("running-turn"); } else if (!m_animation.IsPlaying("running-turn")) { m_startedTurningRound = false; playerState = GruntState.Walking; } } else if (playerState == GruntState.Standing) { if (!m_animation.IsPlaying(m_lastKnownIdle)) { m_currentAnimation = "idle-" + Random.Range(0, 2); m_lastKnownIdle = m_currentAnimation; m_animation[m_currentAnimation].speed = Random.Range(10, 30) / 100.0f; m_animation.CrossFade(m_currentAnimation); } } else if (playerState == GruntState.Jumping) { m_currentAnimation = "run-jump"; if (!m_animation.IsPlaying("run-jump")) { m_animation.Play("run-jump"); } } else if (playerState == GruntState.FallJumping) { m_currentAnimation = "falling"; if (!m_animation.IsPlaying("falling")) { m_animation.CrossFade("falling"); } } else if (playerState == GruntState.FallingFromTower) { m_currentAnimation = "falling"; if (!m_animation.IsPlaying("falling")) { m_animation.CrossFade("falling"); } } }
public void OnFixedUpdate(ref GruntState playerState, ref int movingDirection, CGruntPhysics physics, FootMaterial footMaterial, bool isDetected) { if (playerState == GruntState.Walking) { if (isDetected) { m_currentAnimation = "run"; if (!m_animation.IsPlaying("run")) { m_animation.CrossFade("run", 0.2f); PlayFootstepAudio(footMaterial); } } else { m_currentAnimation = "walk"; if (!m_animation.IsPlaying("walk")) { m_animation.CrossFade("walk", 0.2f); PlayFootstepAudio(footMaterial); } } } else if (playerState == GruntState.Turning) { m_currentAnimation = "walk180turn"; if (!m_animation.IsPlaying("walk180turn") && !m_startedTurningRound) { Debug.Log("On turn start"); m_startedTurningRound = true; m_animation["walk180turn"].speed = 1.0f; m_animation.CrossFade("walk180turn"); } else if (!m_animation.IsPlaying("walk180turn")) { m_startedTurningRound = false; playerState = GruntState.Walking; Debug.Log("On turn complete"); /* * if( movingDirection == 1) * { * movingDirection = -1; * } * else if( movingDirection == -1 ) * { * movingDirection = 1; * } */ } } else if (playerState == GruntState.Attacking) { m_currentAnimation = "alert_attack1"; if (!m_animation.IsPlaying("alert_attack1") && !m_startedAttacking) { Debug.Log("On attack start"); m_startedAttacking = true; m_animation["alert_attack1"].speed = 1.0f; m_animation.CrossFade("alert_attack1"); PlayAttackSound(); } else if (!m_animation.IsPlaying("alert_attack1")) { m_startedAttacking = false; playerState = GruntState.Walking; Debug.Log("On attack complete"); } } else if (playerState == GruntState.Standing) { if (!m_animation.IsPlaying(m_lastKnownIdle)) { if (isDetected) { m_currentAnimation = "alert-idle-" + Random.Range(0, 1); m_animation[m_currentAnimation].speed = 1.0f; } else { m_currentAnimation = "idle-" + Random.Range(0, 2); m_animation[m_currentAnimation].speed = Random.Range(10, 30) / 100.0f; } m_lastKnownIdle = m_currentAnimation; m_animation.CrossFade(m_currentAnimation); } } else if (playerState == GruntState.Jumping) { m_currentAnimation = "run-jump"; if (!m_animation.IsPlaying("run-jump")) { m_animation.Play("run-jump"); } } else if (playerState == GruntState.FallJumping) { m_currentAnimation = "falling"; if (!m_animation.IsPlaying("falling")) { m_animation.CrossFade("falling"); } } else if (playerState == GruntState.FallingFromTower) { m_currentAnimation = "falling"; if (!m_animation.IsPlaying("falling")) { m_animation.CrossFade("falling"); } } }
public void OnFixedUpdate(ref GruntState playerState, ref int movingDirection, CGruntPhysics physics, FootMaterial footMaterial, bool isDetected) { if (playerState == GruntState.Walking) { if(isDetected) { m_currentAnimation = "run"; if (!m_animation.IsPlaying("run")) { m_animation.CrossFade("run", 0.2f); PlayFootstepAudio(footMaterial); } } else { m_currentAnimation = "walk"; if (!m_animation.IsPlaying("walk")) { m_animation.CrossFade("walk", 0.2f); PlayFootstepAudio(footMaterial); } } } else if (playerState == GruntState.Turning) { m_currentAnimation = "walk180turn"; if (!m_animation.IsPlaying("walk180turn") && !m_startedTurningRound) { Debug.Log("On turn start"); m_startedTurningRound = true; m_animation["walk180turn"].speed = 1.0f; m_animation.CrossFade("walk180turn"); } else if (!m_animation.IsPlaying("walk180turn")) { m_startedTurningRound = false; playerState = GruntState.Walking; Debug.Log("On turn complete"); /* if( movingDirection == 1) { movingDirection = -1; } else if( movingDirection == -1 ) { movingDirection = 1; } */ } } else if (playerState == GruntState.Attacking) { m_currentAnimation = "alert_attack1"; if (!m_animation.IsPlaying("alert_attack1") && !m_startedAttacking) { Debug.Log("On attack start"); m_startedAttacking = true; m_animation["alert_attack1"].speed = 1.0f; m_animation.CrossFade("alert_attack1"); PlayAttackSound(); } else if (!m_animation.IsPlaying("alert_attack1")) { m_startedAttacking = false; playerState = GruntState.Walking; Debug.Log("On attack complete"); } } else if (playerState == GruntState.Standing) { if (!m_animation.IsPlaying(m_lastKnownIdle)) { if( isDetected ) { m_currentAnimation = "alert-idle-" + Random.Range(0, 1); m_animation[m_currentAnimation].speed = 1.0f; } else { m_currentAnimation = "idle-" + Random.Range(0, 2); m_animation[m_currentAnimation].speed = Random.Range(10, 30) / 100.0f; } m_lastKnownIdle = m_currentAnimation; m_animation.CrossFade(m_currentAnimation); } } else if (playerState == GruntState.Jumping) { m_currentAnimation = "run-jump"; if (!m_animation.IsPlaying("run-jump")) m_animation.Play("run-jump"); } else if (playerState == GruntState.FallJumping) { m_currentAnimation = "falling"; if (!m_animation.IsPlaying("falling")) m_animation.CrossFade("falling"); } else if (playerState == GruntState.FallingFromTower) { m_currentAnimation = "falling"; if (!m_animation.IsPlaying("falling")) m_animation.CrossFade("falling"); } }