private void Update() { // Check if the deployed animation has already played. if (!_deployed) { if (_spriterAnimator == null) { _spriterAnimator = GetComponent <SpriterDotNetBehaviour>().Animator; _animationList = _spriterAnimator.GetAnimations().ToList(); } // Initially get the sniper's position relative to the camera view _GOpos = Camera.main.WorldToViewportPoint(transform.position); // KEEP CHECKING IF THE SNIPER IS WITHIN THE SCREEN TO ENSURE THE PLAYER SEES THE DEPLOY ANIMATION if (_GOpos.x > 0.1f && _GOpos.x < 0.9f && _GOpos.y > 0.1 && _GOpos.y < 0.9F) { StartCoroutine(DeployDelay()); _deployed = true; } } else { if (_currentIndex != _previousIndex) { Play(_currentIndex); _previousIndex = _currentIndex; } } }
private string GetAnimation(int animationNum) { List <string> animations = _animator.GetAnimations().ToList(); _landingDuration = animations[0].Length * 0.001f; return(animations[animationNum]); }
private void Update() { if (_spriterAnimator == null) { _spriterAnimator = GetComponent <SpriterDotNetBehaviour>().Animator; _animationList = _spriterAnimator.GetAnimations().ToList(); } if (_collisionState.OnSolidGround) { if (Time.time - _timer > 1.0f) { _controller.SetButtonPressTime(Buttons.MoveRight); _walkingMovementRequest.RequestMovement(Buttons.MoveRight); if (_currentIndex != _previousIndex) { Play(_currentIndex); _previousIndex = _currentIndex; } } } else { _timer = Time.time; } }
private static string GetAnimation(UnityAnimator animator, int offset) { List <string> animations = animator.GetAnimations().ToList(); int index = animations.IndexOf(animator.CurrentAnimation.Name); index += offset; if (index >= animations.Count) { index = 0; } if (index < 0) { index = animations.Count - 1; } return(animations[index]); }
// This is not Unity. This is SpriterDotNetUnity. This code is based on an example // straight from the developer. 1. generate a list of all the avaialbe animations. // 2. get the index of the animation you are looking for. 3. Offset the index to find the // correct animation. private string GetAnimation(int offset) { if (_animator != null) { List <string> animations = _animator.GetAnimations().ToList(); int index = animations.IndexOf(_animator.CurrentAnimation.Name); index += offset; if (index >= animations.Count) { index = 0; } if (index < 0) { index = animations.Count - 1; } return(animations[index]); } return("error"); }
private void Update() { if (_spriterAnimator == null) { _spriterAnimator = GetComponent <SpriterDotNetBehaviour>().Animator; _animationList = _spriterAnimator.GetAnimations().ToList(); } _grounded = _collisionState.OnSolidGround; _currentIndex = _shotgunGO.isActiveAndEnabled ? 0 : 23; // Check if the shotgun or the machine gun is active _currentIndex += !_grounded ? 0 : 6; // Check if the player is falling or is on the ground. // If the player is on the ground, check if the player is standing still or running. if (_currentIndex == 6 || _currentIndex == 29) { _currentIndex += _controller.GetButtonPress(Buttons.MoveLeft) || _controller.GetButtonPress(Buttons.MoveRight) ? 6 : 0; } if (_controller.GetButtonPress(Buttons.AimDown) || _controller.GetButtonPress(Buttons.AimLeft) || _controller.GetButtonPress(Buttons.AimRight) || _controller.GetButtonPress(Buttons.AimUp) || _controller.GetButtonPress(Buttons.Shoot)) { switch (_controller.AimDirection) { case 0: case 180: _currentIndex += 3; break; case 45: case 135: _currentIndex += 2; break; case 90: _currentIndex += 1; break; case 270: _currentIndex += 5; break; case 225: case 315: _currentIndex += 4; break; default: _currentIndex += 3; break; } } if (_grounded) { if (_controller.GetButtonPress(Buttons.MoveLeft) && _controller.GetButtonPress(Buttons.AimRight) || _controller.GetButtonPress(Buttons.MoveRight) && _controller.GetButtonPress(Buttons.AimLeft)) { _currentIndex += 5; } } if (_currentIndex != _previousIndex) { Play(_currentIndex); _previousIndex = _currentIndex; } }