- Home /
No answer has been provided and I don't need the question answered, and it has been too long so i don't have the answer myself anymore
OnMouseUp only partially working in Android?
I have a code on the player model that allows you to drag and release when tapping on the player. upon release, the player charges forward, while doing so, a countdown timer will run and the player will have a boxcollider activated. the boxcollider collides with enemies and deal damage to them. when the countdown ends, the boxcollider is disabled again and the movement of the player is completely halted. This works perfectly in unity but when running it on a android device, it only partially works. Here's the code:
void OnMouseUp (){
if (canCharge)
{
mouseDragging = false;
// PlayerController.destinationPosition = Vector3.zero;
/*if (overrideVelocity) {
// cancel existing velocity
GetComponent<Rigidbody> ().AddForce (-GetComponent<Rigidbody> ().velocity, ForceMode.VelocityChange);
} */
// add new force
int snapD = 1;
if (snapDirection == SnapDir.away){ snapD = -1; }
GetComponent<Rigidbody> ().AddForce (snapD * forceVector, forceTypeToApply);
myCollider.enabled = true;
chargeTimeSetter = true;
dragZone.GetComponent<Renderer> ().enabled = false;
}
}
I know for a fact that it's the onmouseup function. it seems that it only wants to execute 1 thing, which is the addForce function, but the mycolllider and chargeTimeSetter booleans are either completely ignored, or somehow not set to true.
Similarly, if you put one of the booleans in the code BEFORE adding force to the player, the addForce is completely ignored.
Does anyone have any idea how to combat this? I've tried moving it to the update function, which ruined the code, making the player ALWAYS move. I've also tried using an if statement with Input.OnTouchEnded, but that made no difference.
Follow this Question
Related Questions
How to drag object along with dragging touch? 1 Answer
Stagnant in Android game mode 0 Answers
Rocket-styled angular drag 0 Answers
Move a cube with mouse relative to the camera rotation 0 Answers
Move object with physic with drag 0 Answers