Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
using System.Collections; using System.Collections.Generic; using UnityEngine; public class GamerChange : MonoBehaviour { [SerializeField]private Rigidbody2D[] rigidbodies; [SerializeField]private float[] speeds; [SerializeField]private float[] jumpForces; [SerializeField]private List<Player> players; [SerializeField]private float checkRadius; [SerializeField]private LayerMask whatIsGround; private float moveInput; private int activePlayer = 0; private bool isGrounded; private void Update() { for (int i = 1; i <= feetPositions.Count; i++) { isGrounded = Physics2D.OverlapCircle(feetPositions[i].position, checkRadius, whatIsGround); } moveInput = Input.GetAxisRaw("Horizontal"); rigidbodies[activePlayer].velocity = new Vector2(moveInput * speeds[activePlayer] * Time.deltaTime, rigidbodies[activePlayer].velocity.y); if(Input.GetKeyDown(KeyCode.Q)) { if (activePlayer < players.Count - 1) activePlayer++; else activePlayer = 0; } if(isGrounded == true && Input.GetKeyDown(KeyCode.Space)) { rigidbodies[activePlayer].velocity = new Vector2(rigidbodies[activePlayer].velocity.x, jumpForces[activePlayer]); } } } [System.Serializable] public class Player { public List<Transform> feetPositions; }