Question by
GEFFStudios · Sep 25, 2017 at 10:45 PM ·
movement scripttransform.positionscipting
Trying to make a cube move up a set amount
I'm trying to raise a cube object to a specific distance, then when it's at that distance i want to have it move the same distance in the opposite direction on a second button press. here's the code i have so far
public float speed = 5f;
private bool inRange;
// Use this for initialization
void Start() {
inRange = false;
}
// Update is called once per frame
void Update() {
if (inRange == true && Input.GetButtonDown("Stop"))
{
transform.Translate(0, speed * Time.deltaTime, 0);
}
}
void OnGUI()
{
GUI.Label(new Rect(10, 25, 100, 20), inRange.ToString());
}
void OnTriggerEnter(Collider other)
{
inRange = true;
}
void OnTriggerExit(Collider other)
{
inRange = false;
}
} I have tried looking up youtube tutorials to no avail. if someone could walk me through how i would do this, that would be great. Thanks in advance!
Comment
Your answer
Follow this Question
Related Questions
SImple, but how do I check a game object's position in an If statement? 1 Answer
how to make the player move in only 2 directions? 0 Answers
How can I use both mouse and keyboard to do the same thing? [SOLVED] 1 Answer
Can someone help me rewriting my script from transform.position to transform.Translate? 1 Answer
My code is not cycling through an array as expected 1 Answer