Пример #1
0
    private void SetMoveTouch(Touch touch)
    {
        if (!startMoveTouch.Equals(nullTouch))
        {
            return;
        }

        startMoveTouch = touch;
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        // if screen was touched at least once, run tests
        if (Input.touchCount > 0)
        {
            // storing first touch into touch variable
            Touch touch = Input.GetTouch(0);

            // checking touch phase
            if (touch.Equals(TouchPhase.Began))
            {
                startTime = Time.time;
                startPos  = touch.position;
            }
            // if touch has ended (lifted finger from device)
            else if (touch.phase == TouchPhase.Ended)
            {
                endTime = Time.time;
                endPos  = touch.position;

                // gives us distance between two points
                swipeDistance = (endPos - startPos).magnitude;
                // gives us duration of swipe
                swipeTime = endTime - startTime;

                // if swipe time and distance are within our boundaries
                if (swipeTime < maxTime && swipeDistance > minSwipeDist)
                {
                    swipe();
                }
            }
        }
    }
Пример #3
0
    void Movement()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            if (touch.position.y < screenHeight / 3 && !touch.Equals(null) && _grounded == true)
            {
                _rigid.velocity  = Vector2.up * jumpForce;
                _grounded        = false;
                _resetJumpNeeded = true;
                health--;
                UpdateHealth();
                StartCoroutine(ResetJumpNeededRoutine());
            }
        }

        RaycastHit2D hitDownInfo = Physics2D.Raycast(transform.position, Vector2.down, .4f, 1 << 6);

        if (hitDownInfo.collider != null)
        {
            if (_resetJumpNeeded == false)
            {
                _grounded = true;
            }
        }
    }
Пример #4
0
    private bool isActionTouch(Touch touch)
    {
        if (!startActionTouch.Equals(nullTouch))
        {
            if (startActionTouch.fingerId == touch.fingerId)
            {
                return(true);
            }
        }

        if (touch.phase == TouchPhase.Began)
        {
            if (touch.position.x > Screen.width / 2)
            {
                return(true);
            }
        }

        return(false);
    }
Пример #5
0
    public override void Update()
    {
        if (Input.touchCount > 0)
        {
            if (fingerId != -1)
            {
                //Vector2 posTouch = new Vector2 (P.pocP ( ((t.position.x / Screen.width) - 0.5f)*2f, Side.WIDTH), P.pocP (((t.position.y / Screen.height) - 0.5f)*2f, Side.HEIGHT));
                //Vector2.Distance(posTouch, transform.position) <= 0.5f
                Touch t = default(Touch);

                for (int i = 0; i < Input.touchCount; i++)
                {
                    if (Input.touches [i].fingerId == fingerId)
                    {
                        t = Input.touches [i];
                    }
                }
                if (t.Equals(default(Touch)))
                {
                    fingerId = -1;
                    dragging = false;
                    return;
                }
                Vector2 posTouch = new Vector2(P.pocP(((t.position.x / Screen.width) - 0.5f) * 2f, Side.WIDTH), P.pocP(((t.position.y / Screen.height) - 0.5f) * 2f, Side.HEIGHT));
                switch (t.phase)
                {
                case TouchPhase.Began:
                    if (Vector2.Distance(posTouch, transform.position) <= 0.5f)
                    {
                        dragging = true;
                    }
                    break;

                case TouchPhase.Moved:
                    if (dragging)
                    {
                        transform.position = posTouch;
                        if (onPlayerMove != null)
                        {
                            onPlayerMove(gameObject);
                        }
                    }
                    break;

                case TouchPhase.Canceled:
                case TouchPhase.Ended:
                    dragging = false;
                    fingerId = -1;
                    break;
                }
            }
            else
            {
                for (int i = 0; i < Input.touchCount; i++)
                {
                    Touch   t        = Input.GetTouch(i);
                    Vector2 posTouch = new Vector2(P.pocP(((t.position.x / Screen.width) - 0.5f) * 2f, Side.WIDTH), P.pocP(((t.position.y / Screen.height) - 0.5f) * 2f, Side.HEIGHT));
                    if (t.fingerId != otherPlayer.fingerId && Vector2.Distance(posTouch, transform.position) <= 0.5f)
                    {
                        fingerId = t.fingerId;
                        Update();
                        return;
                    }
                }
            }
            if (isMaster)
            {
                for (int i = 0; i < Input.touchCount; i++)
                {
                    Touch   t        = Input.GetTouch(i);
                    Vector2 posTouch = new Vector2(P.pocP(((t.position.x / Screen.width) - 0.5f) * 2f, Side.WIDTH), P.pocP(((t.position.y / Screen.height) - 0.5f) * 2f, Side.HEIGHT));
                    if (!(Vector2.Distance(posTouch, transform.position) <= 0.5f || Vector2.Distance(posTouch, otherPlayer.transform.position) <= 0.5f) && !switched)
                    {
                        if (t.fingerId != otherPlayer.fingerId || t.fingerId != fingerId)
                        {
                            switched       = true;
                            fingerSwitchId = t.fingerId;
                            if (onColorSwitchSignal != null)
                            {
                                onColorSwitchSignal();
                            }
                        }
                    }
                    else if (t.fingerId == fingerSwitchId && (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled))
                    {
                        switched       = false;
                        fingerSwitchId = -1;
                    }
                }
            }
        }
    }
Пример #6
0
    override public void Update()
    {
        ParticleSystemRenderer ren = GetComponentInChildren <ParticleSystemRenderer>();

        ren.material.color = ren.trailMaterial.color = gameSettings.GetComponent <GameSettings>().playerColors[playerNumber];


        if (GetComponent <PhotonView>().ownerId == PhotonNetwork.player.ID)
        {
            //THIS IS THE OWNER


            //update speeds
            float tempSpeed = MOVEMENT_SPEED;
            float tempMax   = MAX_SPEED;
            if (myPowerUp != powerUp.NONE)
            {
                timer += Time.deltaTime;
            }

            if (timer > 5)
            {
                timer     = 0;
                myPowerUp = powerUp.NONE;
            }

            if (myPowerUp == powerUp.SPEED)
            {
                tempSpeed += 1;
                tempMax   += 1;
            }



            //MOVEMENT
            int verticalMovement   = 0;
            int horizontalMovement = 0;

#if UNITY_STANDALONE
            if (Input.GetKey(thisMovement[MOVE_UP]))
            {
                verticalMovement += 1;
            }

            if (Input.GetKey(thisMovement[MOVE_DOWN]))
            {
                verticalMovement -= 1;
            }

            if (Input.GetKey(thisMovement[MOVE_RIGHT]))
            {
                horizontalMovement += 1;
            }

            if (Input.GetKey(thisMovement[MOVE_LEFT]))
            {
                horizontalMovement -= 1;
            }
#endif

            //Controls for Android devices
#if UNITY_ANDROID
            Touch touch = Input.GetTouch(0);

            if (!touch.Equals(null))
            {
                horizontalMovement = (int)(touch.deltaPosition.x);
                verticalMovement   = (int)(touch.deltaPosition.y);
            }
#endif

            xVel += horizontalMovement * tempSpeed * Time.deltaTime;
            yVel += verticalMovement * tempSpeed * Time.deltaTime;

            if (horizontalMovement == 0)
            {
                xVel -= Time.deltaTime * MOVEMENT_FRICTION * Mathf.Sign(xVel);
            }
            if (verticalMovement == 0)
            {
                yVel -= Time.deltaTime * MOVEMENT_FRICTION * Mathf.Sign(yVel);
            }

            if (Mathf.Abs(xVel) > tempMax)
            {
                xVel = tempMax * Mathf.Sign(xVel);
            }

            if (Mathf.Abs(xVel) < 0.2f && horizontalMovement == 0)
            {
                xVel = 0;
            }

            if (Mathf.Abs(yVel) > tempMax)
            {
                yVel = tempMax * Mathf.Sign(yVel);
            }

            if (Mathf.Abs(yVel) < 0.2f && verticalMovement == 0)
            {
                yVel = 0;
            }



            Vector3 move = (Vector3.up * yVel) + (Vector3.right * xVel);
            //move.Normalize();



            gameObject.transform.Translate(move);
        }
        else
        {
            //THIS IS ANOTHER PLAYER
        }

        //BOTH

        if (myPowerUp == powerUp.WIND)
        {
            GetComponent <SphereCollider>().radius = PLAYER_WIND_RADIUS;
            ParticleSystem ps = GetComponentInChildren <ParticleSystem>();

            ParticleSystem.ShapeModule shape = ps.shape;
            shape.radius = PLAYER_PARTICLE_WIND_RADIUS;

            ParticleSystem.EmissionModule emit = ps.emission;
            emit.rateOverTime = PLAYER_EMIT_WIND;
        }
        else
        {
            GetComponent <SphereCollider>().radius = PLAYER_RADIUS;
            ParticleSystem ps = GetComponentInChildren <ParticleSystem>();

            ParticleSystem.ShapeModule shape = ps.shape;
            shape.radius = PLAYER_PARTICLE_WIND_RADIUS;

            ParticleSystem.EmissionModule emit = ps.emission;
            emit.rateOverTime = PLAYER_EMIT;
        }
    }
    // Update is called once per frame
    public virtual void Update()
    {
        //update colors

        /*if (gameSettings.GetComponent<GameSettings>().playerColors.Length >= 2)
         * {
         *  ParticleSystemRenderer ren = GetComponentInChildren<ParticleSystemRenderer>();
         *  ren.material.color = ren.trailMaterial.color = gameSettings.GetComponent<GameSettings>().playerColors[playerNumber];
         * }*/


        //update speeds
        float tempSpeed = MOVEMENT_SPEED;
        float tempMax   = MAX_SPEED;

        if (myPowerUp != powerUp.NONE)
        {
            timer += Time.deltaTime;
        }



        int verticalMovement   = 0;
        int horizontalMovement = 0;
        int zMovement          = 0;

#if UNITY_STANDALONE
        if (Input.GetKey(thisMovement[MOVE_DOWN]))
        {
            zMovement -= 1;
        }

        if (Input.GetKey(thisMovement[MOVE_RIGHT]))
        {
            horizontalMovement += 1;
        }

        if (Input.GetKey(thisMovement[MOVE_LEFT]))
        {
            horizontalMovement -= 1;
        }

        if (Input.GetKey(thisMovement[MOVE_FORWARD]))
        {
            zMovement += 1;
        }
#endif

        //Controls for Android devices
#if UNITY_ANDROID
        Touch touch = Input.GetTouch(0);

        if (!touch.Equals(null))
        {
            horizontalMovement = (int)(touch.deltaPosition.x);
            //verticalMovement = (int)(touch.deltaPosition.y );
            zMovement = (int)(touch.deltaPosition.z);
        }
#endif
        xVel += horizontalMovement * tempSpeed * Time.deltaTime;
        //yVel += verticalMovement * tempSpeed * Time.deltaTime;
        zVel += zMovement * tempSpeed * Time.deltaTime;

        if (horizontalMovement == 0)
        {
            xVel -= Time.deltaTime * MOVEMENT_FRICTION * Mathf.Sign(xVel);
        }
        if (zMovement == 0)
        {
            zVel -= Time.deltaTime * MOVEMENT_FRICTION * Mathf.Sign(yVel);
        }

        if (Mathf.Abs(xVel) > tempMax)
        {
            xVel = tempMax * Mathf.Sign(xVel);
        }

        if (Mathf.Abs(xVel) < 0.2f && horizontalMovement == 0)
        {
            xVel = 0;
        }

        if (Mathf.Abs(zVel) > tempMax)
        {
            zVel = tempMax * Mathf.Sign(yVel);
        }

        if (Mathf.Abs(zVel) < 0.2f && zMovement == 0)
        {
            zVel = 0;
        }



        Vector3 move = (Vector3.forward * zVel) + (Vector3.right * xVel);
        //move.Normalize();



        gameObject.transform.Translate(move);
    }