Question by
pronay · Jan 13, 2017 at 06:49 PM ·
transform.positionchild object
child object transform.position not working properly
So I have a child gameobject assigned to Player (also a gameobject). The child is a 3D Text that i have assigned to a variable called popuptext. I am trying to edit its position to make it move upward slowly on collision with a popup in the game. The problem is that it doesn't seem to be moving upwards as intended. Here is my code :
IEnumerator PopUpTexter() {
popuptext.SetActive(true);
step = speed * Time.deltaTime;
Debug.Log (step);
var initPosition = popuptext.transform.position;
var currentPosition = initPosition;
var targetPosition = initPosition;
targetPosition.y += 30;
while(currentPosition != targetPosition)
{
popuptext.transform.position = Vector3.MoveTowards(popuptext.transform.position, targetPosition, step);
currentPosition = popuptext.transform.position;
Debug.Log (currentPosition);
}
popuptext.transform.position = initPosition;
yield return new WaitForSeconds(1);
popuptext.SetActive(false);
}
any help would be appreciated.
Comment
Your answer
Follow this Question
Related Questions
Why are my bullets spawning only from the original muzzle transform? 1 Answer
Child object not rotating as parent 0 Answers
Object stops lerping when target is far away 0 Answers
How to check if transform.position reaches target.position? 2 Answers
What is the result of adding transform.position and transform.right? 1 Answer