void Update()
    {
        //if (Input.GetButton("Fire1") && Time.time > nextFire)
        //{

        //}

        float moveHorizontal = MovementJoystick.GetAxis("Horizontal");
        float moveVertical   = MovementJoystick.GetAxis("Vertical");


        Vector3 movement = new Vector3(moveHorizontal, moveVertical, 0.0f);

        rigidbody.velocity = Vector3.Lerp(movement * speed * Time.smoothDeltaTime, rigidbody.velocity, 0.3f);

        rigidbody.position = new Vector3(
            Mathf.Clamp(rigidbody.position.x, boundary.xMin, boundary.xMax),
            Mathf.Clamp(rigidbody.position.y, boundary.yMin, boundary.yMax),
            0.0f
            );

        rigidbody.rotation = Quaternion.Lerp(
            Quaternion.Euler(((rigidbody.velocity.y * 4.0f - rigidbody.velocity.x) * tilt) + 2.0f, 90.0f, -100.0f),
            rigidbody.rotation,
            0.2f
            );
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        var movement = new Vector3(
            MovementJoystick.GetAxis("Horizontal"),
            0f,
            MovementJoystick.GetAxis("Vertical"));

        CommonMovementMethod(movement);
    }
示例#3
0
    // Called every physics update
    void FixedUpdate()
    {
        // Get input from joysticks
        Vector2 move  = new Vector2(moveStick.GetAxis("Horizontal"), moveStick.GetAxis("Vertical"));
        Vector2 shoot = new Vector2(shootStick.GetAxis("Horizontal"), shootStick.GetAxis("Vertical"));

        // Call the control script to move and shoot the tank
        control.Control(move, shoot);
    }
    void Update()
    {
        float moveHorizontal = MovementJoystick.GetAxis("Horizontal");
        float moveVertical   = MovementJoystick.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, moveVertical, 0.0f);

        GetComponent <Rigidbody>().velocity = movement * speed;
        //if (rigidbody.velocity.magnitude > 0.3)
        //{
        //	Debug.Log("velocity: " + rigidbody.velocity.magnitude.ToString());
        //	Debug.Log("moveHorizontal: " + moveHorizontal.ToString());
        //	Debug.Log("moveHorizontal: " + moveVertical.ToString());
        //}


        GetComponent <Rigidbody>().rotation = Quaternion.Lerp(
            Quaternion.Euler(((GetComponent <Rigidbody>().velocity.y * 4.0f - GetComponent <Rigidbody>().velocity.x) * tilt) + 2.0f, 90.0f, -100.0f),
            GetComponent <Rigidbody>().rotation,
            0.2f
            );
    }
    void  UpdateSmoothedMovementDirection()
    {
        Transform cameraTransform = Camera.main.transform;
        bool      grounded        = IsGrounded();

        // Forward vector relative to the camera along the x-z plane
        Vector3 forward = cameraTransform.TransformDirection(Vector3.forward);

        forward.y = 0;
        forward   = forward.normalized;

        // Right vector relative to the camera
        // Always orthogonal to the forward vector
        Vector3 right = new Vector3(forward.z, 0, -forward.x);

        float v = Input.GetAxisRaw("Vertical") + MovementJoystick.GetAxis("Vertical");
        float h = Input.GetAxisRaw("Horizontal") + MovementJoystick.GetAxis("Horizontal");

        isMoving = Mathf.Abs(h) > 0.1f || Mathf.Abs(v) > 0.1f;

        // Target direction relative to the camera
        Vector3 targetDirection = h * right + v * forward;

        // Grounded controls
        if (grounded)
        {
            if (targetDirection != Vector3.zero)
            {
                moveDirection = targetDirection.normalized;
            }

            float curSmooth = speedSmoothing * Time.deltaTime;

            float targetSpeed = Mathf.Min(targetDirection.magnitude, 1.0f) * runSpeed;

            moveSpeed = Mathf.Lerp(moveSpeed, targetSpeed, curSmooth);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (RotateJoystick != null)
        {
            float rotationX = RotateJoystick.GetAxis("Horizontal") * RotationSpeed * Time.deltaTime;
            float rotationY = RotateJoystick.GetAxis("Vertical") * RotationSpeed * Time.deltaTime;
            _parentTransformCache.Rotate(0f, rotationX, 0f, Space.World);
            _parentTransformCache.Rotate(-rotationY, 0f, 0f);
        }

        /*
         * if (Target != null)
         * {
         *  if (RotateJoystick != null)
         *  {
         *      float rotation = RotateJoystick.GetAxis("Horizontal");
         *      _transformCache.RotateAround(Target.position, Vector3.up, rotation * RotationSpeed * Time.deltaTime);
         *  }
         *  _transformDifference = _transformCache.position - Target.position;
         *
         *  _transformCache.position = Target.position + _transformDifference.normalized * _transformDistance;
         * }
         */
    }
    // Fixed update is performed on each physic update (Delta time).
    void FixedUpdate()
    {
        if (canClimb)
        {
            float verticalAxis = 0.0f;

            if (isMobile)
            {
                verticalAxis = joyStickAxis.GetAxis("Vertical");
            }
            else
            {
                verticalAxis = Input.GetAxis("Vertical");
            }
            Debug.Log("VerticalAxis: " + verticalAxis);
            if (verticalAxis > 0.0f && !topOfLadder)
            {
                transform.position += Vector3.up / 10f;
            }
            else if (verticalAxis < 0.0f)
            {
                transform.position -= Vector3.up / 10f;
            }
        }

        Ray        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0.0f));
        RaycastHit hit;

        // Perform a ray cast down the Z axis relative to the camera transform, with a distance of 2.5 units.
        if (Physics.Raycast(ray, out hit, 2.5f))
        {
            bool actionPressed = isMobile ? mobileControls.GetAction() : Input.GetAxisRaw("Action") == 1;

            // If the object the ray intersects with is a battery (Battery Tag)
            if (hit.collider.tag == "Battery")
            {
                hoveringOverInteractable = true;

                // Get the Halo effect component for the game object and enable it if the cursor is over it.
                halo         = (Behaviour)hit.collider.gameObject.GetComponent("Halo");
                halo.enabled = true;

                // If the action button is pressed (Defined in InputManager under Axes). E on PC X on controller.
                if (actionPressed)
                {
                    // Remove the game object from the scene.
                    Destroy(hit.collider.gameObject);
                    hoveringOverInteractable = false;
                    halo.enabled             = false;
                    // Add a random amount of battery life to the flashlight.
                    LightHandler.AddBatteryLife(Random.Range(30, 45));
                }
            }
            else if (hit.collider.tag == "Clock")
            {
                hoveringOverInteractable = true;

                // Get the Halo effect component for the game object and enable it if the cursor is over it.
                halo         = (Behaviour)hit.collider.gameObject.GetComponent("Halo");
                halo.enabled = true;

                // If the action button is pressed (Defined in InputManager under Axes). E on PC X on controller.
                if (actionPressed)
                {
                    // Remove the game object from the scene.
                    Destroy(hit.collider.gameObject);
                    hoveringOverInteractable = false;
                    halo.enabled             = false;
                    GameManager.AddTime(Random.Range(10, 20));
                }
            }
            else if (hit.collider.tag == "Key")
            {
                hoveringOverInteractable = true;

                // Get the Halo effect component for the game object and enable it if the cursor is over it.
                halo         = (Behaviour)hit.collider.gameObject.GetComponent("Halo");
                halo.enabled = true;

                // If the action button is pressed (Defined in InputManager under Axes). E on PC X on controller.
                if (actionPressed)
                {
                    // Remove the game object from the scene.
                    Destroy(hit.collider.gameObject);
                    hoveringOverInteractable = false;
                    halo.enabled             = false;
                    hasKey = true;
                }
            }
            else if (hit.collider.tag == "Door")
            {
                hoveringOverInteractable = true;

                if (actionPressed)
                {
                    if (hit.collider.transform.localEulerAngles.y < 91.0f)
                    {
                        hit.collider.gameObject.transform.localEulerAngles += new Vector3(0.0f, 2.5f, 0.0f);
                    }
                }
            }
            else if (hit.collider.tag == "DoorExit")
            {
                hoveringOverInteractable = true;

                if (actionPressed)
                {
                    hoveringOverInteractable = false;
                    if (hasKey)
                    {
                        GameManager.gameOver = true;
                    }
                }
                // There was no ray cast intersection within the rays trace distance.
            }
            else
            {
                hoveringOverInteractable = false;
                if (halo != null)
                {
                    halo.enabled = false;
                }
            }
        }
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        if (Joystick.activeInHierarchy)
        {
            var movement = new Vector2(
                MovementJoystick.GetAxis("Horizontal"),
                MovementJoystick.GetAxis("Vertical"));

            CommonMovementMethod(movement);

            // Joystick at Center
            if (movement.x == 0)
            {
                //Idle Animation
                if (thisPC.facingLeft == false)
                {
                    anim.SetInteger("MoveState", 10);
                }

                if (thisPC.facingLeft == true)
                {
                    anim.SetInteger("MoveState", -10);
                }
            }
            //movement left
            if (movement.x <= -0.1f)
            {
                //Change Direction Data
                if (thisPC.facingLeft == false)
                {
                    pv.RPC("FacedLeft", PhotonTargets.AllBuffered);
                }

                //Left Walk Animation
                anim.SetInteger("MoveState", -1);

                //Movement
                player.transform.position = new Vector3(player.transform.position.x - movementSpeed, player.transform.transform.position.y, -10);
            }


            //movement right
            if (movement.x >= 0.1f)
            {
                //Change Direction Data
                if (thisPC.facingLeft == true)
                {
                    pv.RPC("FacedRight", PhotonTargets.AllBuffered);
                }

                //Left Walk Animation
                anim.SetInteger("MoveState", 1);

                //Movement
                player.transform.position = new Vector3(player.transform.position.x + movementSpeed, player.transform.transform.position.y, -10);
            }

            //movement front
            if (movement.y <= -0.6f)
            {
            }

            //movement back
            if (movement.y >= 0.6f)
            {
            }

            if (Input.GetAxisRaw("Horizontal") > 0)
            {
                transform.eulerAngles = new Vector2(0, 0);
            }

            if (Input.GetAxisRaw("Horizontal") < 0)
            {
                transform.eulerAngles = new Vector2(0, 180);
            }
        }
    }
    void Update()
    {
        if (health > maxHealth)
        {
            health = maxHealth;
        }
        if (energy > maxEnergy)
        {
            energy = maxEnergy;
        }
        energySlider.value = energy;
        healthSlider.value = health;
        level = PlayerPrefs.GetFloat("level");
        if (findedRoom == 1)
        {
            findedRoom = 2;
            rooms      = GameObject.FindGameObjectsWithTag("room");
            rooms      = GameObject.FindGameObjectsWithTag("room");
            for (int i = 0; i < rooms.Length; i++)
            {
                if (rooms[i].name == "StartRoom(Clone)")
                {
                    transform.position = rooms[i].transform.position;
                    room = rooms[i];
                    break;
                }
            }
        }
        if (findedRoom == 2)
        {
            rooms = GameObject.FindGameObjectsWithTag("room");
            if (rooms.Length != 0)
            {
                for (int i = 0; i < rooms.Length; i++)
                {
                    if (Mathf.Abs(rooms [i].transform.position.x - transform.position.x) < rooms [i].GetComponent <RoomScript> ().width&&
                        Mathf.Abs(rooms [i].transform.position.y - transform.position.y) < rooms [i].GetComponent <RoomScript> ().height)
                    {
                        room = rooms [i];
                        break;
                    }
                    if (i == rooms.Length - 1 && GameObject.Find("Transaction Camera(Clone)") == null)
                    {
                        for (int b = 0; b < rooms.Length; b++)
                        {
                            if (rooms[b].name == "StartRoom(Clone)")
                            {
                                transform.position = rooms[b].transform.position;
                                room = rooms[b];
                                break;
                            }
                        }
                    }
                }
            }
            movement = new Vector3(MovementJoystick.GetAxis("Horizontal"), MovementJoystick.GetAxis("Vertical"), 0f);
                #if UNITY_EDITOR
            movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0f);
                #endif
            rigidbody2D.AddForce(movement * movementSpeed * Time.deltaTime * 60);
            if (movement.sqrMagnitude != 0)
            {
                transform.rotation = Quaternion.Lerp(transform.rotation,
                                                     Quaternion.LookRotation(Vector3.forward, movement),
                                                     Time.deltaTime * RotationSpeed);
            }
            if (rigidbody2D.velocity.sqrMagnitude > 0.01f)
            {
                int index = (int)(Time.timeSinceLevelLoad * framesPerSecond);
                index = index % sprites.Length;
                spriteRenderer.sprite = sprites [index];
            }
            if (health <= 0 && !GodMode)
            {
                Application.LoadLevel("Menu");
                PlayerPrefs.SetInt("DidLosed", 1);
                PlayerPrefs.SetFloat("level", 1);
                PlayerPrefs.SetInt("HasSeporator", 0);
                PlayerPrefs.SetInt("HasDamagator", 0);
                PlayerPrefs.SetInt("NumberOfDNA", 0);
            }
        }
        levelText.text = level.ToString();

/////////////////////////////////////////////////////////////BIGLASER////////////////////////////////////////////////////////////////////////////////////////////

        if (isBigLaserFiring)
        {
            k += Time.deltaTime;
            if (k >= BigShotDuration)
            {
                isBigLaserFiring = false;
                k = 0;
            }
            if (k >= 1f)
            {
                GameObject     gun      = GameObject.FindGameObjectWithTag("MyGun");
                Quaternion     rotation = gun.transform.rotation;
                Vector3        position = gun.transform.position;
                RaycastHit2D[] hits     = Physics2D.RaycastAll(position, rotation * Vector2.up, 100);
                for (int i = 1; i < hits.Length; i++)
                {
                    if (!hits [i].collider.isTrigger && hits [i].collider.gameObject.tag != "barrier" && hits [i].collider.gameObject.tag != "dynamicBarrier" && hits[i].collider.gameObject.tag != "drop")
                    {
                        hit = hits [i];
                        if (hit.collider.gameObject.tag == "enemy")
                        {
                            hit.collider.gameObject.GetComponent <EnemyBehaviour> ().health -= 10;
                        }
                        break;
                    }
                }
                if (hit.collider != null && !hit.collider.isTrigger)
                {
                    if (FirstFrameShooting)
                    {
                        EndOfLaserClone = Instantiate(EndOfLaser, hit.point, Quaternion.LookRotation(hit.point - new Vector2(transform.position.x, transform.position.y))) as GameObject;
                        EndOfLaserClone.GetComponent <SpriteRenderer>().color = Color.magenta;
                    }
                    EndOfLaserClone.transform.position = hit.point;
                    EndOfLaserClone.transform.rotation = Quaternion.LookRotation(Vector3.forward, hit.point - new Vector2(transform.position.x, transform.position.y));
                    for (int c = 0; c < 5; c++)
                    {
                        GLDebug.DrawLine(position + (rotation * Vector3.right * 0.015f * c),
                                         hit.point + new Vector2((rotation * Vector2.right * 0.015f * c).x, (rotation * Vector2.right * 0.015f * c).y), Color.magenta);
                        GLDebug.DrawLine(position - (rotation * Vector3.right * 0.015f * c),
                                         hit.point - new Vector2((rotation * Vector2.right * 0.015f * c).x, (rotation * Vector2.right * 0.015f * c).y), Color.magenta);
                    }
                }
                FirstFrameShooting = false;
            }
        }
        else
        {
            FirstFrameShooting = true;
            Destroy(EndOfLaserClone);
        }
        //	StartCoroutine (GameObject.FindGameObjectWithTag("MyGun").GetComponent<GunScript>().StartCoroutine (MachinGun()));
    }
示例#10
0
    // Update is called once per frame
    void Update()
    {
        if (PlayerPrefs.GetInt("HasSeporator") == 1 && tag == "MyGun")
        {
            hasSeporator = true;
        }
        if (PlayerPrefs.GetInt("HasPrism") == 1 && tag == "MyGun")
        {
            hasPrism = true;
        }
        if (PlayerPrefs.GetInt("HasDamagator") == 1 && tag == "MyGun")
        {
            hasDamagator = true;
        }
        if (this.gameObject.tag == "MyGun")
        {
            if (controlsType == 1)
            {
                rotation = new Vector3(rotationJoystick.GetAxis("Horizontal"), rotationJoystick.GetAxis("Vertical"), 0f);
                if (rotation.sqrMagnitude > 0)
                {
                    transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(Vector3.forward, rotation), Time.deltaTime * RotationSpeed);
                }
            }
            else if (controlsType == 2)
            {
                if (Input.touchCount > 0)
                {
                    for (int l = 0; l < Input.touchCount; l++)
                    {
                        if (Input.GetTouch(l).phase == TouchPhase.Began &&
                            ((Input.GetTouch(l).position.x) > Screen.width * 0.3 || (Input.GetTouch(l).position.y) > Screen.height * 0.3))
                        {
                            currTouchID = Input.GetTouch(l).fingerId;
                            //		nullRotation = false;
                        }
                        else if ((Input.GetTouch(l).phase == TouchPhase.Moved || Input.GetTouch(l).phase == TouchPhase.Stationary) && Input.GetTouch(l).fingerId == currTouchID)
                        {
                            currTouch    = Input.GetTouch(l);
                            nullRotation = false;
                            break;
                        }
                        else if (Input.GetTouch(l).phase == TouchPhase.Ended && Input.GetTouch(l).fingerId == currTouchID)
                        {
                            currTouchID  = -1;
                            nullRotation = true;
                        }
                        else
                        {
                            nullRotation = true;
                        }
                    }
                    rotation = Vector3.zero;
                    if (!nullRotation)
                    {
                        rotation = new Vector3(currTouch.position.x, currTouch.position.y) - Camera.main.WorldToScreenPoint(transform.position);
                    }
                    if (rotation.sqrMagnitude > 0.01f)
                    {
                        transform.rotation = Quaternion.Euler(new Vector3(0, 0, Mathf.Atan2(rotation.y, rotation.x) * Mathf.Rad2Deg - 90f));
                    }
                }
                else
                {
                    rotation = Vector3.zero;
                }
            }

                        #if UNITY_EDITOR
            rotation = new Vector3(Input.GetAxis("Left-Right"), Input.GetAxis("Up-Down"), 0f);
            if (rotation.sqrMagnitude > 0)
            {
                transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(Vector3.forward, rotation), Time.deltaTime * RotationSpeed);
            }
                        #endif
        }
        else
        {
            if (smartFire)
            {
                rotation = force * k * (player.transform.position - transform.position).magnitude * new Vector3(player.rigidbody2D.velocity.x, player.rigidbody2D.velocity.y, 0) + player.transform.position - transform.position;
            }
            else
            {
                rotation = player.transform.position - transform.position;
            }
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(Vector3.forward, rotation), Time.deltaTime * RotationSpeed);
        }
    }