/// @param reward /// The reward to display /// @param origin /// The origin position of the particles /// @param destination /// The destination of the particles /// public void Initialise(string currencyID, Vector3 origin, Vector3 destination) { // Show the reward at the origin position m_icon.SafeSprite(GameUtils.GetCurrencySprite(currencyID)); transform.localScale = Vector3.zero; transform.position = origin; var burstTime = m_burstTime.GetRandomValue() * m_timeScale; var moveTime = burstTime * 0.5f; var randomBurstPosition = Vector3.right * m_burstDistance.GetRandomValue() + Vector3.up * m_burstDistance.GetRandomValue(); // Burst the reward m_rewardSequence = DOTween.Sequence(); m_rewardSequence.Append(transform.DOScale(1.0f, burstTime).SetEase(Ease.OutBack)); m_rewardSequence.Insert(0.00f, transform.DOBlendableMoveBy(randomBurstPosition, burstTime)); m_rewardSequence.Insert(0.00f, transform.DOBlendableMoveBy(Vector3.up * Screen.width * 0.05f, moveTime)); m_rewardSequence.Insert(moveTime, transform.DOBlendableMoveBy(Vector3.down * Screen.width * 0.05f, moveTime)); // Make the reward fly to its destination m_rewardSequence.AppendInterval(m_idleTime.GetRandomValue()); m_rewardSequence.Append(transform.DOMove(destination, moveTime).SetEase(Ease.InBack)); // Destroy itself on completion m_rewardSequence.AppendCallback(() => { OnReachedDestination.SafeInvoke(); Destroy(gameObject); }); m_rewardSequence.OnComplete(() => { OnRewarded.SafeInvoke(); }); m_rewardSequence.Play(); }
private void Update() { if (_ragDoll) { _ragDollObject.SetActive(true); gameObject.SetActive(false); } if (_runToDeath) { Vector3 destinationPos = new Vector3(_elevator.transform.position.x, _transformRoot.position.y, _transformRoot.position.z); if (!_insideTheElevator) { _transformRoot.position += Vector3.right * Time.deltaTime * movementSpeed * 5; } return; } if (_transformRoot.parent == _elevator.transform) { Vector3 Position = new Vector3(0, yOffset, 0); _transformRoot.localPosition = Position; } if (_moveForward) { Vector3 destinationPos = new Vector3(_myWaitPosition.transform.position.x, _transformRoot.position.y, _transformRoot.position.z); if (Vector3.Distance(_transformRoot.position, destinationPos) < 0.5f) { _animator.Idle(); _reachedWaitPos = true; OnReachedDestination?.Invoke(this); } if (!_reachedWaitPos) { _animator.Walk(); _transformRoot.position += Vector3.right * Time.deltaTime * movementSpeed; } } if (_moveToElevator) { _animator.Walk(); Vector3 destinationPos = new Vector3(_elevator.transform.position.x, _transformRoot.position.y, _transformRoot.position.z); if (!_insideTheElevator) { _transformRoot.position += Vector3.right * Time.deltaTime * movementSpeed; } } if (_moveToDespawn) { _transformRoot.LookAt(_mySpawnPosition.transform); _transformRoot.position += Vector3.left * Time.deltaTime * movementSpeed * 4; } }
private void Update() { if (Idle.Length > 0) { if (animPlayingGotPoints && Time.time - timeGotPointsStarted > 0.4f) { animPlayingGotPoints = false; currentIndexAnim = 0; } if (animPlayingGotPoints) { currentIndexAnim = (currentIndexAnim + Time.deltaTime * 8) % GotPoints.Length; spriteRenderer.sprite = GotPoints[(int)(currentIndexAnim)]; } else { currentIndexAnim = (currentIndexAnim + Time.deltaTime * 8) % Idle.Length; spriteRenderer.sprite = Idle[(int)(currentIndexAnim)]; } } if (gameManager.GameInProgress) { transform.rotation = Quaternion.AngleAxis((int)OrientationLawnMower * -90, Vector3.forward); float distance = Vector3.Distance(Destination, transform.position); if (Time.deltaTime * Speed < distance) { transform.Translate(Vector3.up * Time.deltaTime); } else { GetPoint(); transform.position = Destination; Vector3 newDestination = FindDestination(); if (Destination == newDestination) { IsStuck = true; } else { IsStuck = false; } Destination = newDestination; OnReachedDestination?.Invoke(new Vector2Int((int)Destination.x, (int)Destination.y), OrientationLawnMower); } } }
private void Move() { if (_moving) { transform.Translate((_targetPosition - (Vector2)transform.position).normalized * (Time.deltaTime * _speed)); if (Vector2.Distance(_targetPosition, transform.position) < 0.1) { transform.position = _targetPosition; _moving = false; OnReachedDestination?.Invoke(this); } } }