Пример #1
0
        public IEnumerator MoveTo(Vector3 direction, Vector3 rotation)
        {
            if (playerController.IsDead)
            {
                yield break;
            }
            if (!isMooving)
            {
                isMooving = true;
                Vector3 endPosition = new Vector3
                                          (Mathf.Round(transform.position.x), Mathf.Round(transform.position.y), Mathf.Round(transform.position.z)) + direction;

                if (RaycastPositionChecker.Check(endPosition, "Obstacle"))
                {
                    isMooving = false;
                    yield break;
                }

                jumpSound.pitch = UnityEngine.Random.Range(0.9f, 1.1f);
                jumpSound.Play();

                if (transform.parent != null && direction != Vector3.forward && direction != Vector3.back)
                {
                    endPosition = transform.localPosition + direction;

                    DOTween.Sequence()
                    .Append(transform.DOLocalJump(endPosition, jumpPower, 1, moveDuration))
                    .Join(transform.DOLocalRotate(rotation, moveDuration)).SetAutoKill(true);

                    yield return(new WaitForSeconds(moveDuration + dwellingTime));

                    Debug.Log(dwellingTime);
                    isMooving = false;

                    yield break;
                }

                DOTween.Sequence()
                .Append(transform.DOJump(endPosition, jumpPower, 1, moveDuration))
                .Join(transform.DORotate(rotation, moveDuration)).SetAutoKill(true);

                CallMoveDirectionEvents(direction, endPosition);

                yield return(new WaitForSeconds(moveDuration));

                isMooving = false;
            }
        }
Пример #2
0
        private void StartSpawningAction()
        {
            int levelBorders = (int)LevelBorders.rightBorderPosition.x;

            for (int i = -levelBorders; i < levelBorders; i++)
            {
                if (spawnChance > Random.Range(0f, 1f))
                {
                    Vector3 spawnPosition = new Vector3(transform.position.x + i, transform.position.y, transform.position.z);

                    if (RaycastPositionChecker.Check(spawnPosition, "Obstacle"))
                    {
                        continue;
                    }

                    objectPool.OnSpawnObject(coinPrefab.name, spawnPosition, Quaternion.identity, transform);
                }
            }
        }