Unity 2017 move two different objects simultaneously on Android

0

I'm trying to make a kind of Pong for Android. I have a GameObject for each player, differentiating between them by the Tag they carry. In principle I programmed the controls for OnMouseDown () and OnMouseDrag (), but I realized that in the mobile only detects a click, so that only one GameObject can be moved simultaneously. It is the first time that I make a game for Android, so I do not have much idea of how to pass the mouse to tactile controls. My script is as follows:

public int speed1;
public int speed2;

void OnMouseDown() {
    startPos = transform.position;
    dist = Camera.main.WorldToScreenPoint(transform.position);
    posX = Input.mousePosition.x - dist.x;
    posY = Input.mousePosition.y - dist.y;
    posZ = Input.mousePosition.z - dist.z;
}

void OnMouseDrag() {
    float disX = Input.mousePosition.x - posX;
    float disY = Input.mousePosition.y - posY;
    float disZ = Input.mousePosition.z - posZ;
    Vector3 lastPos = Camera.main.ScreenToWorldPoint(new Vector3(disX, disY, disZ));
    float Zposition = lastPos.z + (speed * Time.deltaTime);
    if (Zposition <= -4.15f) {
        Zposition = -4.15f;
    } else if (Zposition >= 4.15f) {
        Zposition = 4.15f;
    }
    if (CompareTag ("Player")) {
        transform.position = new Vector3 (startPos.x, startPos.y, Zposition * speed1);
    } else if (CompareTag ("Player2")) {
        transform.position = new Vector3 (startPos.x, startPos.y, Zposition * speed2);
    }
}
    
asked by Leandrolo15 29.04.2018 в 12:45
source

0 answers