Question by
belove6893 · Mar 12, 2017 at 02:08 PM ·
movingstopupdate function
stop moving after some distance
HI, i'm new in unity. I create a game that after click the "forward" button, the player will move a distance that i given and stop. Now the problem was the code is in the update function and i cant stop the player for keep moving. Could someone help me about this? using UnityEngine; using System.Collections;
public class run : MonoBehaviour {
public float store = 0;
public GameObject player;
float speed = 10f;
bool updateOn = false;
float n = 1;
// Use tyerhis for initialization
void Start () {
player = GameObject.FindWithTag("Player");
}
// Update is called once per frame
void Update () {
if (updateOn == true) {
if(store != 0){
n = speed;
player.transform.Translate (transform.forward * n * Time.deltaTime);
store--;
}
updateOn = false;
}
}
public void Keep () {
store = +1;
}
public void Run(){
updateOn = true;
}
}
Comment