private void Start() { State = SpiderAIState.Moving; PreviousState = State; attackSpeed = 0.8F; player = GameObject.Find("Player"); spiderRigidbody = GetComponent <Rigidbody2D>(); webCollider = transform.parent.GetComponent <CircleCollider2D>(); spiderWebRadius = transform.parent.GetComponent <CircleCollider2D>().radius; animation = GetComponentInChildren <SpiderAnimation>(); startPosition = transform.position; NewRandomTarget(); RotateTowardsTarget(); }
public void OverridePausedAnimationToIdle() { pausedAnimation = SpiderAnimation.Idle; }
public void SetAnimation(SpiderAnimation newAnim, float speedMult = 1, bool forceStart = false) { //TODO hacky, see if we can assign animator in OnEnable instead if (animator == null) { animator = gameObject.GetComponent <Animator>(); } if (forceStart) { if (newAnim == SpiderAnimation.Walk) { animator.Play("walk", 0, 0); //TODO hacky fix for immediate walk without wait } else if (newAnim == SpiderAnimation.Stand) { animator.Play("threat", 0, 0); //TODO hacky fix for immediate stand without wait } //else if (newAnim == SpiderAnimation.Sit) { // animator.Play("threat", 0, 0); //TODO hacky fix for immediate sit without wait //} else if (newAnim == SpiderAnimation.Idle) { animator.Play("idle", 0, 0); //TODO hacky fix for immediate idle without wait } else { throw new System.Exception("Only allowed to force start walk, stand or idle anims"); } } if (newAnim != currentAnimation || speedMult != lastSpeedMult) { lastSpeedMult = speedMult; CancelAllAnimations(); //if (gameObject.name == "Tarantula") { //Debug.Log(currentAnimation.ToString() + " -> " + newAnim + ": " + speedMult); //} currentAnimation = newAnim; switch (newAnim) { case SpiderAnimation.Idle: SetSpeed(IDLE_SPEED); SetIdle(); break; case SpiderAnimation.TurnLeft: SetSpeed(TURNING_SPEED_MULT * speedMult); SetTurnLeft(); break; case SpiderAnimation.TurnRight: SetSpeed(TURNING_SPEED_MULT * speedMult); SetTurnRight(); break; case SpiderAnimation.Walk: SetSpeed(WALKING_SPEED_MULT * speedMult); SetWalk(); break; case SpiderAnimation.Stand: SetSpeed(STAND_SPEED * speedMult); SetStand(); break; case SpiderAnimation.Sit: SetSpeed(STAND_SPEED * speedMult); SetSit(); break; case SpiderAnimation.Eat: SetSpeed(EAT_SPEED * speedMult); SetEat(); break; case SpiderAnimation.Lower: SetSpeed(speedMult); SetLower(); break; case SpiderAnimation.Descend: //animator.applyRootMotion = true; SetSpeed(speedMult); SetDescend(); break; case SpiderAnimation.Descend2: SetSpeed(speedMult); SetDescend2(); break; case SpiderAnimation.Drop: SetSpeed(speedMult); SetDrop(); break; } } }
public void SetWriggleMode(SpiderWriggleMode newWriggle) { //Debug.Log("Wriggle MODE " + newWriggle.ToString() + ", + " + GetCurrentAnimation()); switch (newWriggle) { case SpiderWriggleMode.Held: ToggleRootMotion(true); if (pausedSpeed == -1) { pausedSpeed = GetSpeed(); pausedAnimation = GetCurrentAnimation(); SetAnimation(SpiderAnimation.Walk); SetSpeed(heldSpeed); } break; case SpiderWriggleMode.HeldAfterDescent: ToggleRootMotion(true); if (pausedSpeed == -1) { pausedSpeed = GetSpeed(); pausedAnimation = GetCurrentAnimation(); SetAnimation(SpiderAnimation.Descend2); SetSpeed(heldSpeed * HELD_SPEED_WHEN_DESCENDING_MULT); } break; case SpiderWriggleMode.Falling: ToggleRootMotion(false); SetSpeed(FALLING_SPEED); break; case SpiderWriggleMode.FallingAfterDescent: ToggleRootMotion(false); SetAnimation(SpiderAnimation.Walk); //Need to rotate by 90 as our previous animation (descent2) was rotated 90deg down gameObject.transform.Rotate(Vector3.right, 90); SetSpeed(FALLING_SPEED); break; case SpiderWriggleMode.Off: ToggleRootMotion(true); if (pausedSpeed != -1) { CancelAllAnimations(); switch (pausedAnimation) { case SpiderAnimation.Idle: SetIdle(); break; case SpiderAnimation.Walk: SetWalk(); break; case SpiderAnimation.TurnLeft: SetTurnLeft(); break; case SpiderAnimation.TurnRight: SetTurnRight(); break; case SpiderAnimation.Descend2: SetIdle(); //Debug.Log("Setting Idle"); break; } SetSpeed(pausedSpeed); pausedSpeed = -1; } break; case SpiderWriggleMode.UpsideDown: CancelAllAnimations(); SetIdle(); SetSpeed(IDLE_SPEED); ToggleRootMotion(true); break; } }
void Start() { _spiderAnimation = transform.parent.gameObject.GetComponentInChildren <SpiderAnimation>(); }
public void TakeDamage(int amount) { // Reduce current health by the amount of damage taken. currentHealth -= amount; // Trigger hurt sound if it exists if (hurtSound != null) { SfxScript.playSound(hurtSound); } // Trigger hurt animation if it exists if (anim != null) { EnemyAnimatorController.ExecuteAnimation(anim, "Hit"); } // Trigger flash if it exists EnemyFlash flash = this.gameObject.GetComponent <EnemyFlash>(); if (flash != null) { StartCoroutine(flash.Flash()); } // If the current health is less than or equal to zero if (currentHealth <= 0) { if (isDead == false) { isDead = true; Debug.Log("Enemy Destroyed!"); if (this.tag == "Enemy" || this.tag == "Boss") { // Increment score when destroyed. Debug.Log("INCREMEMNTING!"); // Increment the score TEMPScoreScript.Instance.IncrementScore(scoreAwarded); } // Play death sound if it exists if (deathSound != null) { SfxScript.playSound(deathSound); } // Play death animation if it exists if (anim != null) { EnemyAnimatorController.ExecuteAnimation(anim, "Die"); } // Play spider aninimation exclusively SpiderAnimation temp = GetComponent <SpiderAnimation>(); if (temp != null) { Debug.Log("THIS IS A SPIDER!"); temp.spiderKilled(); } else { Destroy(gameObject, 1f); } } } }