- Home /
Question by
Long Fall Games · Feb 09, 2014 at 09:17 PM ·
guitransformlerp
NGUI- lerping widget on Y Axis only working in one direction
So I have a widget i want to lerp between two positions as its toggeled. one is at -48 and the other is 0. The idea is when its not being used it will move off-screen.
It lerps off screen perfectly but when i try to move it back (when its turned on) it just snaps to position. I must be missing something.
//Warning Code Dump immenant// using UnityEngine; using System.Collections;
public class toggleMessageBox : MonoBehaviour {
public Transform messageBoxPos;
public float showY=0f;
public float hideY=-48f;
public bool showMessageBox=false;
public float lerpY=0;
public float prevLerpY=0;
public float counter=0;
public float y=0;
// Use this for initialization
void Start ()
{
messageBoxPos = GameObject.Find ("MessageBox").GetComponent<Transform> () as Transform;
}
// Update is called once per frame
void Update ()
{
y = messageBoxPos.position.y;
//update lerpY if needed
if (showMessageBox)
{
lerpY = showY;
}
else
{
lerpY = hideY;
}
//check to see if it changed
if (lerpY != prevLerpY)
{
counter=0;
prevLerpY=lerpY;
}
//get the new position
Vector3 temporaryPosition = messageBoxPos.position;
temporaryPosition = Vector3.Lerp (temporaryPosition, new Vector3 (temporaryPosition.x, lerpY, temporaryPosition.z), counter);
//update the counter
counter += Time.deltaTime;
if (counter > 1)
{
counter = 1;
}
//finally update the position
messageBoxPos.localPosition = temporaryPosition;
}
}
Comment
Ive also noticed the camera is moving on its own but im not sure why >.> ive typed literally 0 code that references the camera and its the root parent