hey all, im trying to make a simple script so if my player object hits the top of ther screen he stops moving up and just stays on screen at the top until he is moved down. and visa versa for the bottom. ive tried using collision on a boundry box with no luck so trying out a script, however im not sure how to go about it
thanks
btw my movement script so far is this
public class Runner : MonoBehaviour {
void Update () {
transform.Translate(5f * Time.deltaTime, 0f, 0f);
if ( Input.GetKey(KeyCode.UpArrow) )
transform.Translate(5f * Time.deltaTime, 20f * Time.deltaTime, 0f);
if ( Input.GetKey(KeyCode.DownArrow) )
transform.Translate(5f * Time.deltaTime, -20f * Time.deltaTime, 0f);
}
}
↧