- Home /
The question is answered, right answer was accepted
stop and start an object going up
Hello, i have a question. my question is how to stop or start my cube going up by clicking the box collider? My cube is going up by this script
void Update() { transform.Translate(Vector3.up * Time.deltaTime, Space.World); }
Answer by MT369MT · Aug 09, 2018 at 01:49 PM
Hi, create a new bool called for example CanMove and then create the function OnMouseDown that detects if you click on the collider with the script attached.
public bool CanMove;
void Update()
{
if (CanMove == true)
{
transform.Translate(Vector3.up * Time.deltaTime, Space.World);
}
}
void OnMouseDown()
{
CanMove = !CanMove;
}
If it isn’t moving and you click it will go up. If it is going up and you click it will stop. Isn’t it what you wanted?
Then i click the box collider my cube stops but i click it again nothing will happen
I tried another time the script and it works fine for me. Are you sure you copied all right?
Follow this Question
Related Questions
Automatically playing animations 1 Answer
Timer that stops at the end of the game 3 Answers
Starting a new animation, after stopping another. Without transitions. 1 Answer
Coroutine start and stop 2 Answers
www Movie Start and Stop 0 Answers