Hello everyone, i have a problem that i have never encountered before , for SOME reason, when i call the Lerp function to simply move a gameobject down by a few pixels, it jumps to some random place in space… I have never encountered anything like this before when using Lerp(), anywayz here is my code :
using UnityEngine;
using System.Collections;
public class Layer2PlayerAnimatorManager : MonoBehaviour {
public float Speed = 0.5f;
public Vector3 targetPos = Vector3.zero;
public bool Move = false;
public bool moving = false;
// Update is called once per frame
void Update () {
if (Input.GetKeyUp (KeyCode.I)) {
gameObject.GetComponent<AnimatedAlpha> ().alpha = 0f;
}
if (Move) {
StartCoroutine(MoveFromTo(transform.position,targetPos,0.5f));
}
}
void OnEnable(){
Messenger<bool>.AddListener ("Skills Button Click", OnMoveToSkills);
Messenger<bool>.AddListener ("Item Button Click", OnMoveToItems);
Messenger<bool>.AddListener ("Equipment Button Click", OnMoveToEquipment);
}
void OnMoveToSkills(bool b){
targetPos = new Vector3 (-280, 127, 0);
Move = true;
}
void OnMoveToItems(bool b){
targetPos = new Vector3 (-280, 96, 0);
Move = true;
}
void OnMoveToEquipment(bool b){
targetPos = new Vector3 (-280, 158, 0);
Move = true;
}
public IEnumerator MoveFromTo(Vector3 pointA, Vector3 pointB, float time) {
if (!moving) { // Do nothing if already moving
moving = true; // Set flag to true
float t = 0;
while (t < 1.0f) {
t += Time.deltaTime / time; // Sweeps from 0 to 1 in time seconds
transform.position = Vector3.Lerp (pointA, pointB, t); // Set position proportional to t
yield return 0; // Leave the routine and return here in the next frame
}
moving = false; // Finished moving
Move = false;
}
}
}
I am using c# messenger extended to send a message from a script on one of my buttons ( using NGUI’s OnClick() event ) to start moving the button to the position it should be, however this does not happen
PS. using the coroutine was just my last attempt, i have tried everything, it may be something simple, but i cant seem to find it, any help would be greatly appreciated!