- Home /
How to animate a moving platform GameObject?
My updated script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CountChildren: MonoBehaviour {
public List<Transform> children = new List<Transform>();
public bool animate;
public bool sendMat;
public Material[] mat;
int time = 5;
void Awake() {
foreach(Transform child in transform) {
children.Clear();
children.Add(child);
}
print(transform.childCount);
for(int i=0; i<children.Count; i++) {
children[i].renderer.sharedMaterial = mat[0];
if(sendMat) BlockLift.ReColor(mat[1]);
}
}
void Update() {
if(animate) {
iTween.MoveTo(gameObject, iTween.Hash("path",iTweenPath.GetPath("pathPlatform"), "time", time));
Debug.LogError("iTweenPath made a path, but this gameObject is not moving along it!");
}
}
}
At runtime, my LogError shows up in the console, and my platform is not moving along the path!
that error is just a form of Debug(), not a real error. and there's no real error showing up... so what's wrong?
Gah my comment got turned into an Answer...anyways what I was saying was "what do you mean??"
how do you put the gameObject on an iTween created path and move it "forward" along that path?
Any and all comments/answers/solutions Wanted! If you know ANYTHING about the errors or why it crashes Unity, please help me!
I was going to post an answer, so I had written it and was ready to hit, "post response" but then I forgot to press that button, and Hibernated my computer. So I had to come back in the morning and hit the button.
Wait a second, does iTween use javascript Hash(es) to make commands? so should i make this script UnityScript?
Answer by fireDude67 · Jun 30, 2011 at 04:24 PM
There's an iTween tutorial on this: http://pixelplacement.com/2010/12/03/visual-editor-for-itween-motion-paths/
That helped for me. Basically you need to assign the Path to the GameObject. I watched the video a long time ago, so correct me if I was wrong.
Edit: First, iTween.MoveTo
needs to be put in Start. Or, if you're doing it differently (need to launch the path later) then you need to set the animate
variable to false
afterwards. Also, I don't see where animate
is getting set. It must be defaulting to true. But, the reason I think now that it is not moving, is because the animate
variable does not get set back to false. Because of that, iTween keeps moving your object back to the start of your path. The way to correct this
void Update() {
if (animate) {
iTween.MoveTo(gameObject, iTween.Hash("path",iTweenPath.GetPath("pathPlatform"), "time", time));
animate = false;
Debug.Log("animate is:" + animate.ToString());
}
}
What that does is use iTween.MoveTo()
as normal, then it sets animate
to false, then it prints the value of animate
. When you run this script, it should output "animate is False" in the Console.
I voted you up because that video was exactly what i need! now with that, I know how to make a moving path. But i had to watch this game on my PC since mac doesn't have flash-player or whatever the plugin he used to make that video, so i'll test it on my mac, and then vote you correct when it works.
I changed my script in my answer, but i still get the same errors!
It still gives me the errors! Do you have any idea why?
Same errors? Are you SURE Path 1 exists? Are you sure it's Path 1 and not Path1? And, have you downloaded the latest version of iTween? Sometimes that does it.
Yes, I'm sure i have the current iTween package, and i copy/pasted the name of the path from the visual path editor to this script.
Answer by Jesus_Freak · Jun 30, 2011 at 09:45 AM
It's because my script has the field:
[ExecuteInEditMode]
and the script "iTweenPath" doesn't. Therefore, while my script is trying to find the path, the iTweenPath script isn't creating the path, at least not for use in any other script yet(until runtime)
but for some reason my platform isn't moving along the path!
I removed the "Is it that" part of your answer and changed it because that makes it sound sooo much like a comment.
oh thanks. but the answer's wrong any way. an int has NOTHING to do with it....
Why'd you mark this as accepted Answer? It doesn't answer your question...does it?
Look it up on YouTube, do a search for iTween and you'll find an example.
Your answer
Follow this Question
Related Questions
changing itween moveTo speed param. 0 Answers
Making a forked path with iTween 1 Answer
3D Text to follow a path; iTween 0 Answers
draw a path in game with touch and move player on it 0 Answers
Scale an iTweenPath 0 Answers