コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        gameTimer        += Time.deltaTime;
        bombRespawnTimer += Time.deltaTime;
        //Debug.Log(gameTimer);
        if (bombRespawnTimer > 10)
        {
            bombCount += 1;
            SetBombCountText();
            bombRespawnTimer = 0;
        }


        //Debug.Log(Input.gyro.rotationRateUnbiased);
        shakoMeter = Input.gyro.rotationRateUnbiased;
        if (shakoMeter.x > 3f || shakoMeter.y > 3f || shakoMeter.z > 2.5f || shakoMeter.x < -3f || shakoMeter.y < -3f || shakoMeter.z < -2.5f)
        {
            Debug.Log("YOU SHAKING!!!!!\nSHAKKINGGG\nSHAKKEEINGG");
        }



        Vector3 moveDirection = new Vector3(Input.GetAxis(getAxisHorizontal), 0.0f, Input.GetAxis(getAxisVertical));

        moveDirectionWithSpeed = moveDirection * speed;

        Vector3 moveDirectionJoystick = new Vector3(joystick.Horizontal, 0.0f, joystick.Vertical);

        moveDirectionWithSpeedJoystick = moveDirectionJoystick * speed;

        wallDirectionJoystick = new Vector3(wallJoystick.Horizontal, 0.0f, wallJoystick.Vertical);


        //this decides if the player is on computer keyboard or mobile device
        if (moveDirection != Vector3.zero)
        {
            combinedMoveDirectionWithSpeed = moveDirectionWithSpeed;
        }
        else
        {
            combinedMoveDirectionWithSpeed = moveDirectionWithSpeedJoystick;
            moveDirection = moveDirectionJoystick;
        }
        //move the player
        rb.velocity = combinedMoveDirectionWithSpeed;

        //rotate the player when it turns
        if (moveDirection != Vector3.zero)
        {
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(moveDirection.normalized), 0.5f);
        }

        //RaycastHit theHit;
        //if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out theHit))
        //{
        //    if (theHit.collider.gameObject.tag == "Wall")
        //    {
        //        Debug.Log("WALLLL!!!!");
        //        distanceFromObj = theHit.distance * 100;
        //    }
        //}


        //DROPPING PREFABS(WALLS AND BOMBS) SECTION

        //bomb cooldown conditional
        if (bombCooldown > 0 && !isBombCooledDown)
        {
            bombCooldown -= Time.deltaTime;
        }
        else if (bombCooldown <= 0)
        {
            isBombCooledDown = true;
        }

        if ((Input.GetKeyDown(KeyCode.Space) && isPlayer1 && bombCount > 0 && isBombCooledDown) || (Input.GetKeyDown(KeyCode.Period) && !isPlayer1 && bombCount > 0 && isBombCooledDown))
        {
            //what to spawn, where to spawn, which direction to spawn in
            Instantiate(bomb, new Vector3(transform.position.x, transform.position.y - 0.4f, transform.position.z) + (transform.forward * 2), transform.rotation);
            bombCount -= 1;
            SetBombCountText();
            bombCooldown     = bombCooldownDefault;
            isBombCooledDown = false;
        }
        else if ((Input.GetKeyDown(KeyCode.Space) && isPlayer1 && bombCount == 0) || (Input.GetKeyDown(KeyCode.Period) && !isPlayer1 && bombCount == 0))
        {
            Debug.Log("Player out of bombs");
            SetBombCountText();
            setWarningText("bomb");
        }



        //WALL INSTANTIATE FOR KEYS
        if ((Input.GetKeyDown(KeyCode.V) && isPlayer1 && wallCount > 0) || (Input.GetKeyDown(KeyCode.Comma) && !isPlayer1 && wallCount > 0))
        {
            Instantiate(wall, transform.position + (transform.forward * 2), transform.rotation);
            wallCount -= 1;
            SetWallCountText();
        }
        else if ((Input.GetKeyDown(KeyCode.V) && isPlayer1 && wallCount == 0) || (Input.GetKeyDown(KeyCode.Comma) && !isPlayer1 && wallCount == 0))
        {
            Debug.Log("Player 1 out of walls");
            SetWallCountText();
            setWarningText("wall");
        }

        if ((Input.GetKeyDown(KeyCode.C) && isPlayer1) || (Input.GetKeyDown(KeyCode.L) && !isPlayer1))
        {
            isCarryingFlag = false;
            flagIsDropped  = true;
            carryFlag.SetActive(false);
            //GameObject.FindWithTag("Flag2").SetActive(true);
        }



        Collider[] zones = Physics.OverlapSphere(transform.position, 0f);
        foreach (Collider zone in zones)
        {
        }

        Collider[] hits = Physics.OverlapSphere(transform.position, overlapColliderRange);
        foreach (Collider hit in hits)
        {
            if ((hit.tag == "Player2" && isCarryingFlag && isPlayer1) || (hit.tag == "Playa" && isCarryingFlag && !isPlayer1))
            {
                isCarryingFlag = false;
                flagIsDropped  = true;
                carryFlag.SetActive(false);
                Debug.Log("TAGGED!!! DROP THE GEM!");
                setWarningText("tagged with gem");
            }
            else if ((hit.tag == "Player2" && isPlayer1 && inDangerZone && !isTagged) || (hit.tag == "Playa" && !isPlayer1 && inDangerZone && !isTagged))
            {
                PlayerController1 taggedPlayerScript = hit.GetComponent <PlayerController1>();

                int wallPenalty = wallCount / 2;
                taggedPlayerScript.wallCount += wallPenalty;
                taggedPlayerScript.SetWallCountText();
                wallCount = wallPenalty;
                SetWallCountText();

                int bombPenalty = bombCount / 2;
                taggedPlayerScript.bombCount += bombPenalty;
                taggedPlayerScript.SetBombCountText();
                bombCount = bombPenalty;
                SetBombCountText();

                isTagged = true;
                Debug.Log("NICE ONE " + hit.tag + "! You took " + wallPenalty + " walls and " + bombPenalty + " bombs");
                setWarningText("tagged");
            }
        }
    }