- Home /
transform.position.z += 1
I want to make my player go forward 1 unit, after waiting. But my player goes forward on local vector3, not my players forward!
Code:
IEnumerator moveFWD(){
print ("before wait");
yield return new WaitForSeconds (5);
charPos = transform.parent.position;
charPos.z += 1;
transform.parent.position = charPos;
print ("after wait");
}
So what's it doing? Are you calling it with StartCoroutine()?
Yes I am, I'm calling this coroutine when i'm looking at something, and in range of it.
Answer by Sindorej · Aug 16, 2014 at 06:43 PM
gameObject.transform.Translate(new Vector3(1,0,0));
@$$anonymous$$r$$anonymous$$elonPie - 'm glad you have a working answer, but your original code was trying to move the parent object. If that was null, you should have been getting a null reference exception error in the console. If that was not null, then you should have seen movement.
Also, please flag robertbu's answer as correct if it helped your find the solution.
Your answer
Follow this Question
Related Questions
Add one on local z axis 3 Answers
yield WaitForSeconds c# 4 Answers
unity3d invoke 0 Answers
Find closest transform 1 Answer