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

How to addForce even after you release the button?

$
0
0
I'm trying to addForce to the game object. But when I release the button he stops, I wanted him to keep moving even after releasing the button. How do I do? Here is the script: using Photon.Pun; using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerScript : MonoBehaviourPun { public Joystick joystick; protected JoyButton joyButton; public ProgressBar progressBar; public GameObject progressBarObj; public float speed = 10f; private bool isLoading; // Start is called before the first frame update void Start() { joystick = FindObjectOfType(); joyButton = FindObjectOfType(); progressBar = FindObjectOfType(); progressBarObj.SetActive(false); } // Update is called once per frame void Update() { var rigidbody = GetComponent(); if (photonView.IsMine) { if (!isLoading) { rigidbody.velocity = new Vector3(joystick.Horizontal * speed, rigidbody.velocity.y, joystick.Vertical * speed); } } if(joyButton.pressed && progressBar.current <= 10) { progressBarObj.SetActive(true); progressBar.current += 0.05f; isLoading = true; } if (!joyButton.pressed && isLoading) { progressBarObj.SetActive(false); rigidbody.AddForce(new Vector3(0, 0, progressBar.current * 10), ForceMode.Impulse); progressBar.current = 0; isLoading = false; } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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