// Aşağıda çok aşağıda bulunan kod var. Her iki topum da kullandığım kontrolden bağımsız olarak aynı anda hareket ediyor. Birisi bana yardım eli verebilir misin?Her iki oyuncunun da aynı anda hareket etmesini nasıl engellerim?
public class PlayerController : MonoBehaviour
{
public float speed = 80.0f; // Code for how fast the ball can move. Also it will be public so we can change it inside of Unity itself.
public GameObject player1; //Player 1 Rigidbody
public GameObject player2; //Player 2 Rigidbody
private Rigidbody rb;
private Rigidbody rb2;
void Start()
{
rb = GetComponent<Rigidbody>();
rb2 = GetComponent<Rigidbody>();
player1 = GameObject.Find("Player");
player2 = GameObject.Find("Player 2");
}
//Player 1 Code with aswd keys
void Player1Movement()
{
if (player1 = GameObject.Find("Player"))
{
if (Input.GetKey (KeyCode.A)) {
rb.AddForce (Vector3.left * speed);
}
if (Input.GetKey (KeyCode.D)) {
rb.AddForce (Vector3.right * speed);
}
if (Input.GetKey (KeyCode.W)) {
rb.AddForce (Vector3.forward * speed);
}
if (Input.GetKey (KeyCode.S)) {
rb.AddForce (Vector3.back * speed);
}
}
}
//Player 2 Code with arrow keys
void Player2Movement()
{
if(player2 = GameObject.Find("Player 2"))
{
if (Input.GetKey(KeyCode.LeftArrow))
{
rb2.AddForce(Vector3.left * speed);
}
if (Input.GetKey(KeyCode.RightArrow))
{
rb2.AddForce(Vector3.right * speed);
}
if (Input.GetKey(KeyCode.UpArrow))
{
rb2.AddForce(Vector3.forward * speed);
}
if (Input.GetKey(KeyCode.DownArrow))
{
rb2.AddForce(Vector3.back * speed);
}
}
}
// Update is called once per frame
void Update()
{
Player1Movement();
Player2Movement();
}
}
Nasıl Oyuncularımın her ikisi de aynı anda hareket etmiyor öyle değiştirebilirim?
Birisi bana yardım edebilir mi? –