protected virtual void Idle(float elapsedTime) { if (IgnoreXYMovement) { return; } // Turn on the screens when he begines to idle if (TimeInCurrentState == 0) { IdleScreenAnimation.Play("Take 001"); foreach (Fader screen in IdleScreens) { screen.FadeIn(); } } ApplyMovingHorizontal(elapsedTime); VerticalSpeed = GroundVerticalSpeed; ApplyBiDirection(); if (!MecanimAnimator.GetBool(MecanimHashes.Fall) && !IsGrounded) { MecanimAnimator.SetBool(MecanimHashes.Fall, true); } if (CharInput.Pickup) { MecanimAnimator.SetBool(MecanimHashes.TurnAround, true); } }
protected void Jump(float elapsedTime) { // Babybot does all its movement midair if (CharInput.Left || CharInput.Right) { ApplyMovingHorizontal(elapsedTime); } // Start moving up at the beginning if (TimeInCurrentState == 0) { if (CharInput.JumpLeft || CharInput.JumpLeftReleased) { HorizontalSpeed = -1.0f * Settings.MaxHorizontalSpeed; } else if (CharInput.JumpRight || CharInput.JumpRightReleased) { HorizontalSpeed = 1.0f * Settings.MaxHorizontalSpeed; } VerticalSpeed = Mathf.Sqrt(2 * Settings.JumpHeight * Settings.Gravity); MecanimAnimator.SetBool(MecanimHashes.Jump, false); } // Fall down at all other times else { ApplyGravity(elapsedTime); } // Babybot is capable of turning around mid-air ApplyBiDirection(); }
protected void UpdateWeaponsAnimations() { // Only do things on the Weapons layer if we can Weapon currentWeapon = GameManager.Inventory.CurrentWeapon; if (currentWeapon == null || IsDead) { return; } // The stealthkill state is a special weapon/base-layer combat state if (CurrentState.fullPathHash != StealthKillState && StealthKillable != null && currentWeapon.CanStealthKill && CharInput.AttackPressed) { MecanimAnimator.SetBool(MecanimHashes.StealthKill, true); StartCoroutine(ShowStealthKill()); } // Enable weapon usage when not in the stealthkill state if (CurrentState.fullPathHash != StealthKillState) { MecanimAnimator.SetBool(MecanimHashes.ShootGun, CharInput.AttackPressed && (currentWeapon.Type == Weapon.WeaponType.Weapon_GravityGun || currentWeapon.Type == Weapon.WeaponType.Weapon_VETO)); MecanimAnimator.SetBool(MecanimHashes.ActivateCamo, CharInput.AttackPressed && currentWeapon.Type == Weapon.WeaponType.Weapon_Camo); MecanimAnimator.SetBool(MecanimHashes.PlaceMine, CharInput.AttackPressed && currentWeapon.Type == Weapon.WeaponType.Weapon_MINE); } }
protected void Hanging(float elapsedTime) { VerticalSpeed = 0; if (MecanimAnimator.GetBool(MecanimHashes.Hang)) { if (ActiveHangTarget == null) { MecanimAnimator.SetBool(MecanimHashes.Fall, true); return; } if (ActiveHangTarget.DoesFaceZAxis()) { HorizontalSpeed = 0.0f; Direction = Vector3.zero; } else { HorizontalSpeed = Direction.x * Settings.LedgeClimbingSpeed; if (IsHangTargetToRight) { Direction = Vector3.right; } else { Direction = Vector3.left; } } MecanimAnimator.SetBool(MecanimHashes.Hang, false); } if (ActiveHangTarget != null) { ActivePlatform = ActiveHangTarget.transform; } MecanimAnimator.SetBool(MecanimHashes.Fall, false); if (ActiveHangTarget == null) { DropHangTarget(); MecanimAnimator.SetBool(MecanimHashes.Fall, true); } else if (ActiveHangTarget is Ledge && (CharInput.Up || InputMoveForward)) { _ledge = ActiveHangTarget as Ledge; MecanimAnimator.SetBool(MecanimHashes.ClimbLedge, true); } else if (CharInput.JumpPressed) { DropHangTarget(); MecanimAnimator.SetBool(MecanimHashes.Jump, true); } else if (CharInput.Down) { DropHangTarget(); MecanimAnimator.SetBool(MecanimHashes.Fall, true); } }
protected void Falling(float elapsedTime) { if (CharInput.Right || CharInput.Left) // maintain horizontal momentum, but slow down if does input { ApplyMovingHorizontal(elapsedTime); } ApplyGravity(elapsedTime); MecanimAnimator.SetBool(MecanimHashes.Fall, false); if (!(ActiveHangTarget is Ledge && ((Ledge)ActiveHangTarget).Obstacle) && (CanHangOffObject && ActiveHangTarget.DoesFaceXAxis() && VerticalSpeed < 0) || (CanHangOffObject && ActiveHangTarget.DoesFaceZAxis() && CharInput.Up)) { MecanimAnimator.SetBool(MecanimHashes.Hang, true); VerticalSpeed = 0; HorizontalSpeed = 0; } else { MecanimAnimator.SetBool(MecanimHashes.Hang, false); } if (CanGrabWall && ((Direction.x > 0 && IsHangTargetToRight) || (Direction.x < 0 && !IsHangTargetToRight))) { MecanimAnimator.SetBool(MecanimHashes.GrabWall, true); } }
public void StartSearch() { if (IsGrounded) { MecanimAnimator.SetBool(MecanimHashes.Search, true); } }
//ClimbingStrafeState = Animator.StringToHash ("Climbing.ClimbingStrafe"); // protected void ClimbingStrafe(float elapsedTime) // { // if(ActiveHangTarget == null) { // DropHangTarget(); // MecanimAnimator.SetBool(MecanimHashes.Fall, true); // return; // } // // ApplyClimbingStrafing(CharInput.Horizontal); // // if(HorizontalSpeed != 0) // ApplyClimbingVertical(vertical); // else // VerticalSpeed = 0.0f; // // if(ActiveHangTarget.DoesFaceZAxis()) // Direction = Vector3.zero; // // MecanimAnimator.SetBool(MecanimHashes.Jump, CharInput.JumpPressed); // // } // WallgrabbingState = Animator.StringToHash("Wall.Wallgrabbing"); protected void Wallgrabbing(float elapsedTime) { // We don't move horizontally HorizontalSpeed = 0; SetMecanimAnimatorHorizontalSpeedFloat(); // But we do want to start moving down the wall if (_wallJumpCount > 0 || TimeInCurrentState > Settings.WallgrabDuration) { VerticalSpeed = Settings.WallSlideSpeed * elapsedTime; } else { VerticalSpeed = 0; } VerticalSpeed = 0; MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed); // You can let go of the wall if (CharInput.PickupPressed) { MecanimAnimator.SetBool(MecanimHashes.Fall, true); MecanimAnimator.SetBool(MecanimHashes.GrabWall, false); DropHangTarget(); // But the expectation is that you will jump off } else if (CharInput.JumpPressed) { MecanimAnimator.SetBool(MecanimHashes.JumpWall, true); MecanimAnimator.SetBool(MecanimHashes.GrabWall, false); DropHangTarget(); } }
// States on the ground from which you can jump should call this method to set up the jump private void AllowGroundJump() { if (!MecanimAnimator.GetBool(MecanimHashes.Jump) && IsGrounded && CharInput.JumpPressed) { if (CharInput.JumpLeft) { Direction = Vector3.left; float jumpSpeedRatio = -1.1f; if (IsSneaking) { jumpSpeedRatio = -0.79f; } HorizontalSpeed = jumpSpeedRatio * Settings.MaxHorizontalSpeed; } else if (CharInput.JumpRight) { Direction = Vector3.right; float jumpSpeedRatio = 1.1f; if (IsSneaking) { jumpSpeedRatio = 0.79f; } HorizontalSpeed = jumpSpeedRatio * Settings.MaxHorizontalSpeed; } SetMecanimAnimatorHorizontalSpeedFloat(); MecanimAnimator.SetBool(MecanimHashes.Jump, true); } }
protected void AcquireTarget(float elapsedTime) { MecanimAnimator.SetBool(MecanimHashes.AcquiringTarget, false); HorizontalSpeed = 0.0f; VerticalSpeed = GroundVerticalSpeed; }
// FallingState = Animator.StringToHash("Air.Falling"); protected void Falling(float elapsedTime) { // Maintain horizontal speed by default, but allow 1/2 the normal movement for horizontal input if (CharInput.Right || CharInput.Left) { ApplyMovingHorizontal(elapsedTime * 0.5f); } // Vertical Motion ApplyGravity(elapsedTime); MecanimAnimator.SetBool(MecanimHashes.Fall, false); // You can grab onto the walls while falling MecanimAnimator.SetBool(MecanimHashes.GrabWall, CanGrabWall); // You can regrab the hangable object you last let go of if (!(ActiveHangTarget is Ledge && ((Ledge)ActiveHangTarget).Obstacle) && (CanHangOffObject && ActiveHangTarget.DoesFaceXAxis() && VerticalSpeed < 0) || (CanHangOffObject && ActiveHangTarget.DoesFaceZAxis() && CharInput.Up)) { MecanimAnimator.SetBool(MecanimHashes.Hang, true); VerticalSpeed = 0; HorizontalSpeed = 0; SetMecanimAnimatorHorizontalSpeedFloat(); MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed); } else { MecanimAnimator.SetBool(MecanimHashes.Hang, false); } }
// RollingState = Animator.StringToHash("Ground.Rolling"); protected void Rolling(float elapsedTime) { // We only need to set motion settings at the beginning of the animation if (!MecanimAnimator.GetBool(MecanimHashes.ClimbLedge)) { return; } // We need to make sure we know what we're going to roll over. if (ActiveHangTarget == null) { Debug.LogWarning("Failed to have hang target while doing rolling!"); return; } // Meta-data about the motion we need to do MecanimAnimator.SetBool(MecanimHashes.ClimbLedge, false); Bounds ledgeBounds = ActiveHangTarget.GetComponent <Collider>().bounds; float animationTime = MecanimAnimator.GetCurrentAnimatorStateInfo(0).length; // Horizontal motion float distanceToMove = Direction.x > 0 ? ledgeBounds.max.x - Controller.bounds.center.x : ledgeBounds.min.x - Controller.bounds.center.x; HorizontalSpeed = distanceToMove / animationTime; SetMecanimAnimatorHorizontalSpeedFloat(); // Vertical motion float distanceToClimb = ledgeBounds.max.y - Controller.bounds.min.y; VerticalSpeed = distanceToClimb / animationTime; MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed); }
public void OnAcquireTarget() { if (IsGrounded) { MecanimAnimator.SetBool(MecanimHashes.AcquiringTarget, true); } }
protected void StealthDeath(float elapsedTime) { if (MecanimAnimator.GetBool(MecanimHashes.StealthDeath)) { MecanimAnimator.SetBool(MecanimHashes.StealthDeath, false); } }
protected override void UpdateMecanimVariables() { if (IgnoreXYMovement) { return; } if (!MecanimAnimator.GetBool(MecanimHashes.Jump) && IsGrounded && CharInput.JumpPressed) { MecanimAnimator.SetBool(MecanimHashes.Jump, true); } bool facingRightLadder = (ActiveHangTarget && ActiveHangTarget.transform.position.x - transform.position.x > 0.0f); bool facingLeftLadder = (ActiveHangTarget && transform.position.x - ActiveHangTarget.transform.position.x > 0.0f); bool startClimbLadder = CanClimbLadder && ((facingRightLadder && CharInput.Right) || (facingLeftLadder && CharInput.Left)); MecanimAnimator.SetBool(MecanimHashes.ClimbLadder, startClimbLadder); /* * if(startClimbLadder) * _autoClimbDir = AutoClimbDirection.AutoClimb_Up; * // if not in a climb, reset our auto-climb direction for use next climb. * if( (CurrentState.fullPathHash != ClimbingLadderState || CurrentState.fullPathHash != ClimbingPipeState) ) * _autoClimbDir = AutoClimbDirection.AutoClimb_None; */ MecanimAnimator.SetBool(MecanimHashes.ClimbRope, CanClimbRope); MecanimAnimator.SetBool(MecanimHashes.IsGrounded, IsGrounded); MecanimAnimator.SetBool(MecanimHashes.AttackHorizontal, CharInput.Attack > 0); MecanimAnimator.SetBool(MecanimHashes.AttackVertical, CharInput.Attack < 0); if (!IsGrounded) { MecanimAnimator.SetBool(MecanimHashes.AcquiringTarget, false); } // Give Olympus some perfectly hard stops on land if (IsLanding) { HorizontalSpeed = 0; } // Knowing direction is useful for the turnaround animation MecanimAnimator.SetFloat(MecanimHashes.XDirection, Direction.x); // Olympus needs to turn off the screens when moving // TODO: THINK OF A MORE EFFICIENT WAY INSTEAD OF DOING THIS EVERY FRAME if (CharInput.Left || CharInput.Right) { foreach (Fader screen in IdleScreens) { screen.FadeOut(); } } }
public override void MakeDamaged(Vector3 knockForce) { MecanimAnimator.SetBool(MecanimHashes.Damaged, true); HorizontalSpeed = knockForce.x; VerticalSpeed = knockForce.y; SetMecanimAnimatorHorizontalSpeedFloat(); MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed); }
protected void GrabWall(float elapsedTime) { if (MecanimAnimator.GetBool(MecanimHashes.GrabWall)) { HorizontalSpeed = 0; VerticalSpeed = 0; MecanimAnimator.SetBool(MecanimHashes.GrabWall, false); } }
// JumpingState = Animator.StringToHash("Jumping.Jumping"); // FrontflipState = Animator.StringToHash("Jumping.Frontflip"); // FrontflipLoopState = Animator.StringToHash("Jumping.FrontflipLoop"); protected void Jumping(float elapsedTime) { // We only determine vertical speed (Horizontal Speed is maintained throughout the jump) if (MecanimAnimator.GetBool(MecanimHashes.Jump)) { float jumpHeight = Settings.JumpHeight; if (CurrentState.fullPathHash == FrontflipState) { jumpHeight *= 1.5f; } VerticalSpeed = Mathf.Sqrt(2 * jumpHeight * Settings.Gravity); MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed); MecanimAnimator.SetBool(MecanimHashes.Jump, false); } else { ApplyGravity(elapsedTime); } // You can increase horizontal speed midair ONLY if doing a sneak jump and you weren't already at max speed if (CurrentState.fullPathHash == JumpingState && (CharInput.Left || CharInput.Right)) { float prevSpeed = HorizontalSpeed; ApplyMovingHorizontal(elapsedTime * 0.5f); if (Mathf.Abs(HorizontalSpeed) < Mathf.Abs(prevSpeed)) { HorizontalSpeed = prevSpeed; } else if (Direction.x > 0 && HorizontalSpeed > 0.79f * Settings.MaxHorizontalSpeed) { HorizontalSpeed = 0.79f * Settings.MaxHorizontalSpeed; } else if (Direction.x < 0 && HorizontalSpeed < -0.79f * Settings.MaxHorizontalSpeed) { HorizontalSpeed = -0.79f * Settings.MaxHorizontalSpeed; } SetMecanimAnimatorHorizontalSpeedFloat(); } // You can grab onto walls while jumping MecanimAnimator.SetBool(MecanimHashes.GrabWall, CanGrabWall); // You can hang off most objects while jumping bool shouldHang = (CanHangOffObject && ActiveHangTarget.DoesFaceXAxis() && VerticalSpeed < 0) || (CanHangOffObject && ActiveHangTarget.DoesFaceZAxis() && CharInput.Up); MecanimAnimator.SetBool(MecanimHashes.Hang, shouldHang); // You can re-grab ropes you just let go of bool shouldRegrabRope = CharInput.Up && PreviousHangTarget != null && PreviousHangTarget.GetComponent <Collider>().bounds.Contains(transform.position); if (shouldRegrabRope) { AddHangTarget(PreviousHangTarget); MecanimAnimator.SetBool(MecanimHashes.ClimbRope, true); } }
// StealthKillState = Animator.StringToHash("Combat.Stealth Kill"); protected void StealthKill(float elapsedTime) { MecanimAnimator.SetBool(MecanimHashes.StealthKill, false); // This is a completely stationary action HorizontalSpeed = 0.0f; VerticalSpeed = 0.0f; SetMecanimAnimatorHorizontalSpeedFloat(); MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed); }
protected void TurnAround(float elapsedTime) { if (MecanimAnimator.GetBool(MecanimHashes.TurnAround)) { MecanimAnimator.SetBool(MecanimHashes.TurnAround, false); StartCoroutine(WaitToChangeDirection()); } HorizontalSpeed = 0; VerticalSpeed = GroundVerticalSpeed; }
// LandingState = Animator.StringToHash("Landing.Landing"); // LandSneakState = Animator.StringToHash("Landing.SneakLanding"); // LandHighState = Animator.StringToHash("Landing.HighLanding"); // LandRollState = Animator.StringToHash("Landing.Rolling"); protected void Landing(float elapsedTime) { // We do hard stops on land unless we're rolling if (TimeInCurrentState == 0) { if (CurrentState.fullPathHash == LandHighState || (CurrentState.fullPathHash != LandRollState && !(CharInput.Left || CharInput.Right))) { HorizontalSpeed = 0; } else if (CurrentState.fullPathHash != LandRollState) { HorizontalSpeed *= 0.5f; } else { ApplyFriction(elapsedTime); } SetMecanimAnimatorHorizontalSpeedFloat(); } // Horizontal Motion mainly wants us to slow down if (CurrentState.fullPathHash != LandHighState && InputMoveForward) { ApplyMovingHorizontal(elapsedTime * 0.5f); } else { if (CurrentState.fullPathHash == LandRollState) { elapsedTime *= 1.5f; } ApplyFriction(elapsedTime); } // Vertical Motion depends on whether we're on the ground if (!IsGrounded) { if (CurrentState.fullPathHash != LandRollState || CurrentState.normalizedTime > 0.99f) { MecanimAnimator.SetBool(MecanimHashes.Fall, true); } else { ApplyGravity(elapsedTime); } } else { VerticalSpeed = GroundVerticalSpeed; MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, GroundVerticalSpeed); } // You can jump again even before you finish landing AllowGroundJump(); }
protected void Running(float elapsedTime) { ApplyMovingHorizontal(elapsedTime); VerticalSpeed = GroundVerticalSpeed; ApplyBiDirection(); if (!MecanimAnimator.GetBool(MecanimHashes.Fall) && !IsGrounded) { MecanimAnimator.SetBool(MecanimHashes.Fall, true); } }
protected void UpdateBaseAnimations() { bool facingRightLadder = (ActiveHangTarget && ActiveHangTarget.transform.position.x - transform.position.x > 0.0f); bool facingLeftLadder = (ActiveHangTarget && transform.position.x - ActiveHangTarget.transform.position.x > 0.0f); bool startClimbLadder = CanClimbLadder && ((facingRightLadder && CharInput.Right) || (facingLeftLadder && CharInput.Left)); MecanimAnimator.SetBool(MecanimHashes.ClimbLadder, startClimbLadder); MecanimAnimator.SetBool(MecanimHashes.ClimbRope, CanClimbRope); MecanimAnimator.SetBool(MecanimHashes.IsGrounded, IsGrounded); }
public IEnumerator ShowDeath(Vector3 knockForce) { MecanimAnimator.SetBool(MecanimHashes.Die, true); HorizontalSpeed = knockForce.x; VerticalSpeed = knockForce.y; yield return(new WaitForSeconds(2.0f)); base.OnDeath(); yield return(new WaitForSeconds(3.0f)); _itemDropper.DropItems(transform.position); }
protected void Searching(float elapsedTime) { if (MecanimAnimator.GetBool(MecanimHashes.Search)) { HorizontalSpeed = 0; VerticalSpeed = GroundVerticalSpeed; MecanimAnimator.SetBool(MecanimHashes.Search, false); } if (!MecanimAnimator.GetBool(MecanimHashes.Fall) && !IsGrounded) { MecanimAnimator.SetBool(MecanimHashes.Fall, true); } }
// DamagedState = Animator.StringToHash("Combat.Damaged"); protected void Damaged(float elapsedTime) { if (MecanimAnimator.GetBool(MecanimHashes.Damaged)) { MecanimAnimator.SetBool(MecanimHashes.Damaged, false); GameManager.UI.EnableInput(); GameManager.UI.CraftingMenu.Close(); GameManager.UI.ShowMap(false); } ApplyGravity(elapsedTime); if (IsGrounded) { ApplyFriction(elapsedTime); } }
// DeathState = Animator.StringToHash("Combat.Death"); // DeadState = Animator.StringToHash("Combat.Waiting For Respawn"); protected void Die(float elapsedTime) { if (IsGrounded) { ApplyFriction(elapsedTime); VerticalSpeed = GroundVerticalSpeed; MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed); } else { ApplyGravity(elapsedTime); } MecanimAnimator.SetBool(MecanimHashes.Jump, false); MecanimAnimator.SetBool(MecanimHashes.Fall, false); MecanimAnimator.SetBool(MecanimHashes.Die, false); }
// WalljumpingState = Animator.StringToHash("Wall.Walljumping"); protected void Walljumping(float elapsedTime) { // Determine motion on the first frame if (MecanimAnimator.GetBool(MecanimHashes.JumpWall)) { Direction = -Direction; HorizontalSpeed = Settings.MaxHorizontalSpeed * Direction.x * 0.79f; SetMecanimAnimatorHorizontalSpeedFloat(); VerticalSpeed = Mathf.Sqrt(2 * Settings.JumpHeight * Settings.Gravity); MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed); _wallJumpCount++; MecanimAnimator.SetBool(MecanimHashes.JumpWall, false); } else { ApplyGravity(elapsedTime); } // You eventually start falling down if (transform.position.y >= LastGroundHeight - 1) { MecanimAnimator.SetBool(MecanimHashes.Fall, false); } // You can do consecutive wall grabs/jumps if (CanGrabWall) { MecanimAnimator.SetBool(MecanimHashes.GrabWall, true); } // You can grab onto ledges if (!(ActiveHangTarget is Ledge && ((Ledge)ActiveHangTarget).Obstacle) && (CanHangOffObject && ActiveHangTarget.DoesFaceXAxis() && VerticalSpeed < 0) || (CanHangOffObject && ActiveHangTarget.DoesFaceZAxis() && CharInput.Up)) { MecanimAnimator.SetBool(MecanimHashes.Hang, true); VerticalSpeed = 0; MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed); HorizontalSpeed = 0; } else { MecanimAnimator.SetBool(MecanimHashes.Hang, false); } }
public IEnumerator ShowStealthDeath() { IgnoreXYMovement = true; yield return(new WaitForSeconds(3.0f)); MecanimAnimator.SetBool(MecanimHashes.StealthDeath, true); yield return(new WaitForSeconds(1.2f)); bool isToRightOfPlayer = transform.position.x > GameManager.Player.transform.position.x; Vector3 directional = isToRightOfPlayer ? Vector3.right : Vector3.left; directional *= 25000; base.OnDeath(directional + Vector3.up * 15000); _itemDropper.DropItems(transform.position); }
// PickupState = Animator.StringToHash("Kneeling.Pickup"); protected void Pickup(float elapsedTime) { // Everything relevant happens on the first frame if (MecanimAnimator.GetBool(MecanimHashes.Pickup)) { MecanimAnimator.SetBool(MecanimHashes.Pickup, false); // Horizontal Motion HorizontalSpeed = 0; SetMecanimAnimatorHorizontalSpeedFloat(); // Vertical Motion VerticalSpeed = GroundVerticalSpeed; MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed); // Pickup a weapon if (_itemPickedup.WeaponPrefab != null) { int pickupCount = _itemPickedup.Quantity; Weapon pickedUpWeapon = _itemPickedup.WeaponPrefab.GetComponent <Weapon>(); if (!GameManager.Inventory.TryAddAmmo(pickedUpWeapon, pickupCount)) { // NOTE: DON'T USE THE OBJECT POOL BECAUSE IT DOESN'T REALLY HAPPEN THAT OFTEN Transform instantiatedWeapon = (Transform)Instantiate(_itemPickedup.WeaponPrefab); Weapon newWeapon = instantiatedWeapon.GetComponent <Weapon>(); newWeapon.Quantity = pickupCount; GameManager.Inventory.Weapons.Add(newWeapon); GameManager.UI.CycleToNextWeapon(); } GameManager.UI.RefreshWeaponWheel(); // Pickup an inventory item } else { InventoryItem newInvItem = InventoryItemFactory.CreateFromType(_itemPickedup.Type, _itemPickedup.Quantity); GameManager.Inventory.AddItem(newInvItem); GameManager.UI.CraftingMenu.RefreshItemWheel(); } // Get rid of the picked up item Destroy(_itemPickedup.gameObject, 0.5f); } }
protected void Jumping(float elapsedTime) { if (Mathf.Abs(CharInput.Horizontal) > 0.1) { ApplyMovingHorizontal(elapsedTime); } if (MecanimAnimator.GetBool(MecanimHashes.Jump)) { if (CharInput.JumpLeft || CharInput.JumpLeftReleased) { Direction = Vector3.left; HorizontalSpeed = -1.0f * Settings.MaxHorizontalSpeed; } else if (CharInput.JumpRight || CharInput.JumpRightReleased) { Direction = Vector3.right; HorizontalSpeed = 1.0f * Settings.MaxHorizontalSpeed; } VerticalSpeed = Mathf.Sqrt(2 * Settings.JumpHeight * Settings.Gravity); MecanimAnimator.SetBool(MecanimHashes.Jump, false); } else { ApplyGravity(elapsedTime); } //ApplyBiDirection(); if (transform.position.y >= LastGroundHeight - 1) { MecanimAnimator.SetBool(MecanimHashes.Fall, false); } MecanimAnimator.SetBool(MecanimHashes.Hang, (CanHangOffObject && ActiveHangTarget.DoesFaceXAxis() && VerticalSpeed < 0) || (CanHangOffObject && ActiveHangTarget.DoesFaceZAxis() && CharInput.Up)); if (CanGrabWall && ((Direction.x > 0 && IsHangTargetToRight) || (Direction.x < 0 && !IsHangTargetToRight))) { MecanimAnimator.SetBool(MecanimHashes.GrabWall, true); } }
void Reset() { animator = GetComponentInChildren<MecanimAnimator>(); }
/// <summary> /// Called when the AI is initialized and the body has been ste. /// Set up gun parenting and grab the AI Animator and the Gun Controller /// </summary> public override void BodyInit() { base.BodyInit(); if (_gunPrefab == null || _gunMount == null) throw new System.Exception("AimAndFireELement requires a Gun Prefab and Gun Mount"); GameObject tGun = (GameObject)GameObject.Instantiate(_gunPrefab); tGun.transform.parent = _gunMount; tGun.transform.localPosition = Vector3.zero; tGun.transform.localRotation = Quaternion.identity; _animator = AI.Animator as MecanimAnimator; if (_animator == null) throw new System.Exception("AimAndFireELement only works with a MecanimAnimator on your AI"); _gunController = tGun.GetComponentInChildren<GunController>(); if (_gunController == null) throw new System.Exception("AimAndFireELement requires a GunController located on the Gun Prefab"); _gunController.shooter = AI.Body; }