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*.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?

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.

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!