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

How to stop code in the update function?

$
0
0
I have some code that when it executes, it pushes a character forward. The issue is that the character never stops moving and continues forever. Is there a way to stop the character from moving after 2 seconds? Here is the code I'm using: public class meleeAttack : MonoBehaviour { public int speed = 500; Collider storedOther; bool isHit = false; void Start() { } void Update() { if (isHit == true ) { storedOther.GetComponent().AddForce(transform.forward * speed); } } void OnTriggerStay(Collider other) { if (other.gameObject.tag == "Player" && Input.GetKeyUp(KeyCode.F)) { storedOther = other; isHit = true; } } } I'm not sure if there's a way to stop the update() function so it stops the character movement.

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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