コード例 #1
0
 // Update is called once per frame
 void Update()
 {
     if (!gameOn)
     {
         for (int i = 1; i < 5; i++)
         {
             if (Input.GetButtonDown("p" + i + "_button_x"))
             {
                 ShuffleTeams();
             }
         }
         for (int i = 1; i < 5; i++)
         {
             if (joyController.GetTackle(i))
             {
                 StartGame();
             }
         }
         for (int i = 1; i < 5; i++)
         {
             if (Input.GetButtonDown("p" + i + "_button_b"))
             {
                 RandomColor(i);
             }
         }
         for (int i = 1; i < 5; i++)
         {
             if (Mathf.Abs(joyController.GetLHorizontal(i)) < 0.1 && Mathf.Abs(joyController.GetLVertical(i)) < 0.1)
             {
                 playerHoldTime[i - 1] = 0;
                 playerPressed[i - 1]  = false;
             }
             else
             {
                 playerHoldTime[i - 1] += Time.deltaTime;
                 if (playerHoldTime[i - 1] > holdTreshold)
                 {
                     UpdateValues(i);
                 }
                 else if (!playerPressed[i - 1])
                 {
                     playerPressed[i - 1] = true;
                     UpdateValues(i);
                 }
             }
         }
     }
 }
コード例 #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);

        pText.transform.position = new Vector3(pos.x, pos.y + offSet, pos.z);

        if (canMove)
        {
            float horizontal = joyController.GetLHorizontal(playerNum);
            float vertical   = joyController.GetLVertical(playerNum);
            if (playerNum == 1)
            {
                //Debug.Log("VERt " + vertical + " hor " + horizontal);
            }
            horizontal = horizontal * Time.deltaTime;
            vertical   = vertical * Time.deltaTime;
            Vector2 velocity = new Vector2(horizontal * accelerationSpeed, vertical * accelerationSpeed);
            if (rb.velocity.magnitude > 5)
            {
                Debug.Log("player " + playerNum + " velo " + rb.velocity.magnitude);
            }
            Move(velocity);
            //Debug.Log("after " + rb.velocity.magnitude);

            if (canTackle && joyController.GetTackle(playerNum))
            {
                StartCoroutine(Tackle());
            }
            if (rb.velocity.magnitude > maxSpeed)
            {
                //Debug.Log("velo " + playerNum +" " + rb.velocity);
                //Vector2 slow = new Vector2(slowSpeed, slowSpeed) * -rb.velocity;
                //Debug.Log("Slow " + playerNum+ " " +slow);
                //rb.AddForce(slow * (float)rb.mass);
                rb.drag = originalDrag + Mathf.Min(rb.velocity.magnitude, originalDrag);
            }
            else
            {
                rb.drag = Mathf.Max(rb.velocity.magnitude, originalDrag);
            }
        }
    }