Im making a puzzle game an im not sure how to do this. There would be a upright cube with a lever(Poll/Stick) sticking out of its side. And when you push the stick it moves in a circle and opens a gate. Any Help?
bump
moar details!
Is the cube and lever on the same model?
Is the level a child object of the cube?
Have you tried rotating the lever?
Do you have any scripts attached to any objects?
THe cube and lever are on the same model. The level is a child object of the cube. I have not tried rotating the lever because i dont know how. And i dont have any script for them yet. I could use animation but im not sure how to make that work in this case.
first, the lever should not be on the cube. Your answer here is a Coroutine. A Coroutine is a function that runs over time and is started by StartCoroutine( functionname(params) )
Basically, it runs and every frame you do a calculation then when it is done you just let it finish.
Pseudo code
startCoroutine{
cont = true
while(cont){
add x * Time.deltaTime to the angle of the leaver
if the lever is greater than maxangle then cont = false
yield
}
lever.angle = maxangle
cont = true
while(cont){
add x to the position of the gate
if the gate is greater than maxposition then cont = false
yield
}
gate.position = maxposition
cont = true
while(cont){
subtract x * Time.deltaTime from the angle of the lever
if the lever is less than minangle then cont = false
yield
}
lever.angle = minangle
}