// Update is called once per frame void Update() { if (Player1P != null && Player2P != null) { Player1P.Translate(Vector3.forward * 5 * Time.deltaTime); Player2P.Translate(Vector3.forward * 5 * Time.deltaTime); if (Input.GetKey(KeyCode.A)) { Player1P.Translate(Vector3.left * Speed * Time.deltaTime); } if (Input.GetKey(KeyCode.D)) { Player1P.Translate(Vector3.right * Speed * Time.deltaTime); } if (Input.GetKey(KeyCode.LeftArrow)) { Player2P.Translate(Vector3.left * Speed * Time.deltaTime); } if (Input.GetKey(KeyCode.RightArrow)) { Player2P.Translate(Vector3.right * Speed * Time.deltaTime); } } else { transform.Translate(Vector3.forward * 5 * Time.deltaTime); } }
private void OnTriggerEnter2D(Collider2D hitInfo) { Player2P player2P = hitInfo.GetComponent <Player2P>(); if (player2P != null) { player2P.TakeDamage(damage); Destroy(gameObject); } Player2 player2 = hitInfo.GetComponent <Player2>(); if (player2 != null) { player2.TakeDamage(damage); Destroy(gameObject); } YPlayer2 player2Y = hitInfo.GetComponent <YPlayer2>(); if (player2Y != null) { player2Y.TakeDamage(damage); Destroy(gameObject); } }