2075 / Unity / 3D / Додатково / Код для двох ракеток
public GameObject leftBat; public GameObject rightBat; void Update () { leftBat.GetComponent<Rigidbody>().velocity = new Vector3(0f, 0f, 0f); rightBat.GetComponent<Rigidbody>().velocity = new Vector3(0f, 0f, 0f); if (Input.GetKey(KeyCode.W)) { //rb.AddForce(transform.right * (200)); leftBat.GetComponent<Rigidbody>().velocity = new Vector3(0f, 6f, 0f); } else if (Input.GetKey(KeyCode.S)) { //rb.AddForce(transform.right * (200)); leftBat.GetComponent<Rigidbody>().velocity = new Vector3(0f, -6f, 0f); } if (Input.GetKey(KeyCode.UpArrow)) { //rb.AddForce(transform.right * (200)); rightBat.GetComponent<Rigidbody>().velocity = new Vector3(0f, 6f, 0f); } else if (Input.GetKey(KeyCode.DownArrow)) { //rb.AddForce(transform.right * (200)); rightBat.GetComponent<Rigidbody>().velocity = new Vector3(0f, -6f, 0f); } }
