Uran
July 20, 2014, 9:30pm
1
If i have 2 cubes, the first is the parent of the second in the hierarchy. How do I aim the relativePath parameter at the child cube?
Here is what I have tried, the code is in a script attached to the parent cube.
private void Test()
{
AnimationClip clip = new AnimationClip();
AnimationCurve curve = new AnimationCurve.Linear(0, 1, 2, 3);
clip.SetCurve("", typeof(Transform), "localPosition.x", curve);
clip.SetCurve("Child", typeof(Transform), "localEulerAngles.x", curve);
animation.AddClip(clip, "test");
animation.Play("test");
}
Obviously, this doesn’t work. The reference(link ), does not really shed any light on how to use the relativePath parameter.
What are you trying to do exactly? Just get the GameObject of the second (child) cube and then add an animation curve onto it so it moves around?
Uran
December 22, 2014, 2:41pm
3
Well, I’m currently implementing a importer for a custom 3d model format, which in turn enables modding. What I’m trying to achieve here is that I have one animation clip that manipulates the children of the object that the clip is assigned to.
Hope this clarifies what I intended with this piece of code. Thank you for your time.
Try this: (not tested)
public Transform childCube;
private void Test()
{
AnimationClip clip = new AnimationClip();
AnimationCurve curve = new AnimationCurve.Linear(0, 1, 2, 3);
clip.SetCurve("", typeof(Transform), "localPosition.x", curve);
clip.SetCurve(childCube.name, typeof(Transform), "localEulerAngles.x", curve);
animation.AddClip(clip, "test");
animation.Play("test");
}