Ejemplo n.º 1
0
    void OnMove(InputValue value)
    {
        if (!isRunning)
        {
            return;
        }

        if (onExplode.IsCompleted)
        {
            return;
        }

        if (movingDirection != null)
        {
            return;
        }

        var v = value.Get <float>();

        if (v == 0)
        {
            return;
        }

        movingDirection = v > 0 ? MovingDirection.Right : MovingDirection.Left;

        Lane.Position nextLanePosition;
        switch (targetLanePosition)
        {
        case Lane.Position.Left:
            nextLanePosition = v > 0 ? Lane.Position.Center : Lane.Position.Left;
            break;

        case Lane.Position.Right:
            nextLanePosition = v > 0 ? Lane.Position.Right : Lane.Position.Center;
            break;

        default:     // Lane.Position.Center
            nextLanePosition = v > 0 ? Lane.Position.Right : Lane.Position.Left;
            break;
        }
        targetLanePosition = nextLanePosition;
    }
Ejemplo n.º 2
0
    void OnEnable()
    {
        isRunning          = false;
        _traveledLength    = 0.0F;
        movingDirection    = null;
        targetLanePosition = Lane.Position.Center;

        explodeCompletionSource = new UniTaskCompletionSource();

        random.InitState((uint)DateTime.Now.ToBinary());

        var rigidbody = GetComponent <Rigidbody>();

        rigidbody.isKinematic = true;

        var position = transform.position;
        var targetX  = lane.GetTargetXFromPosition(targetLanePosition);

        transform.position = new float3(targetX, 0, 0);
        transform.rotation = quaternion.identity;

        body.SetActive(true);
    }