Esempio n. 1
0
    private void DeactivateCollectables()
    {
        for (int i = 0; i < objects.Count; i++)
        {
            objects[i].UiObject.SetActive(false);
        }

        state = CollectableState.Deactivated;
    }
Esempio n. 2
0
    public void Update(Vector3 playerPosition)
    {
        if (state == CollectableState.Enabled)
        {
            timer += Time.deltaTime * 4;
            float sin = Mathf.Sin(timer);

            for (int i = 0; i < objects.Count; i++)
            {
                ObjectData objectData = objects[i];
                Vector3    newPos     = objectData.WorldPosition;
                newPos.x += objects[i].Direction * 0.01f;
                newPos.y  = Mathf.Max(0f, 2.5f * sin);
                objectData.WorldPosition = newPos;
                objects[i] = objectData;
                objects[i].UiObject.transform.position = Camera.main.WorldToScreenPoint(newPos);
            }

            if (sin <= 0)
            {
                state          = CollectableState.Collectable;
                collectionTime = DateTime.Now;
            }
        }
        else if (state == CollectableState.Collectable)
        {
            for (int i = 0; i < objects.Count; i++)
            {
                objects[i].UiObject.transform.position = Camera.main.WorldToScreenPoint(objects[i].WorldPosition);
            }

            if (DateTime.UtcNow.Subtract(collectionTime).TotalSeconds >= 60)
            {
                DeactivateCollectables();
            }
        }
        else if (state == CollectableState.Collected)
        {
            for (int i = 0; i < objects.Count; i++)
            {
                objects[i].WorldPosition =
                    Vector3.MoveTowards(objects[i].WorldPosition, playerPosition, Time.deltaTime * 10);
                objects[i].UiObject.transform.position = Camera.main.WorldToScreenPoint(objects[i].WorldPosition);

                if (Vector3.Distance(objects[i].WorldPosition, playerPosition) < 0.1f)
                {
                    DeactivateCollectables();
                    break;
                }
            }
        }
    }
Esempio n. 3
0
    public void SetState(CollectableState newState, bool force = false)
    {
        _collectable.OnCollectStarted -= SetDisabled;

        if (newState == _state && !force)
        {
            return;
        }
        if (newState == CollectableState.Crystal)
        {
            _platform.gameObject.SetActive(false);
            _collectable.gameObject.SetActive(true);
            _collectable.OnCollectStarted += SetDisabled;
            _collectable.Reset();
        }
        else if (newState == CollectableState.Platform)
        {
            _source.Play();
            _platform.gameObject.SetActive(true);
            _collectable.gameObject.SetActive(false);
            _platform.SetSolid(true);
        }
        _state = newState;
    }
Esempio n. 4
0
 public void SetCollected()
 {
     state = CollectableState.Collected;
 }