i’m trying to make an object move up and then back down, when it is clicked on. This is the script i tried but it didn’t work(this is in the Update function):
if(Active)
{
if(Input.GetMouseButtonUp(0))
{
//animation.Play("Bounce");
bounce = true;
Play();
Debug.Log("Play");
}
}
if(bounce)
{
bool hb = false;
float pos = transform.position.y; //position to be modified
float opos = transform.position.y; //position backup
float tpos = transform.position.y; //target position
tpos = tpos + 1;
if(!hb)
{
if(pos < tpos)
{
pos = tpos * Time.deltaTime;
hb = true;
}
}else if(hb)
{
pos = opos * Time.deltaTime;
hb = false;
}
transform.position = new Vector3(transform.position.x, pos, transform.position.z); //Update the position
}
can anyone tell me what can be done to fix this or if i’m doing it completely wrong.