Question by
hidonut123 · Sep 02, 2015 at 09:43 AM ·
2dvector2translationhookpowerbar
How to make a retracting Tongue?
I've been messing around with the 2D controls in Unity, and have successfully coded a tongue to translate vertically in the Game, but am wondering how to make it retract after some time (1-2 seconds). Similarly, I've had trouble implementing a "power bar" system, where the distance that the tongue reaches is depending on the duration of the button press.
Here is my code (javascript):
#pragma strict
function Start () {
transform.position.z = -0.5;
}
function Update () {
if(Input.GetKeyDown ("space"))
{
moveTo(transform.position.y + 11.8, 20); // Feed the moveTo() function the X/Y positions you want to move it to, and the Speed you want to move at
}
transform.position.z = -0.5;
}
function moveTo(posY : float, speed : float)
{
while (transform.position.y != posY)
{
transform.position = Vector2.MoveTowards (transform.position, new Vector2(transform.position.x, posY), speed * Time.deltaTime);
yield;
}
}
Thanks, any help is appreciated.
Comment