Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

InputGetMouseButton not working on touch

$
0
0
Hi, i`m trying to make an object(the player) moving upside when i hold my finger on the touchscreen of the phone(Android).I just have a big problem, if i try to use this code : void Update() { healthDisplay.text = health.ToString(); if(health<=0) { gameOver.SetActive(true); Destroy(gameObject); } if (Input.GetMouseButton(0)) { rb.AddForce ( new Vector2(0, 45),ForceMode2D.Force); } else if (Input.GetMouseButtonUp(0)) { rb.velocity *= 0.55f; } } It`s only working when i use it on the PC, when i put it on the phone it`s doing nothing. I found a code that`s working (not sure if it`s right): void Update() { healthDisplay.text = health.ToString(); if (health <= 0) { gameOver.SetActive(true); Destroy(gameObject); } if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began || Input.GetMouseButton(0)) { rb.velocity=new Vector2(rb.velocity.x,7); rb.velocity= new Vector2(rb.velocity.x, 7); } } where i use rb.velocity twice, and it`s doing the job but not that smooth like the addforce.Can someone explain me why if i use the addforce on my phone it`s not working? Or how can i do something to get the same result?

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>