- Home /
Blenderで作成したオブジェクトをUnityで正常に再生する方法
Blenderでアニメーション付きのオブジェクトを作成しました。
そのオブジェクトをDuplicateで複数作成させた後に、Unityの実行ボタンを押すと正常に全てのオブジェクトのアニメーションが再生されます。 しかし、アニメーションの再生のタイミングを制御するために、Animatorで一度Emptyを通してboolで条件定義をさせると、一つのオブジェクトのアニメーションしか再生されません。
<コード内容>
using System; using System.Collections.Generic;
namespace UnityEngine.XR.iOS { public class UnityARHitTestExample : MonoBehaviour
{
public Transform m_HitTransform;
public float life_time = 3f;
float time = 0f;
//animation
public Animator anim;
void start () {
time = 0;
anim = GetComponent<Animator> ();
}
bool HitTestWithResultType (ARPoint point, ARHitTestResultType resultTypes)
{
List<ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface ().HitTest (point, resultTypes);
if (hitResults.Count > 0) {
foreach (var hitResult in hitResults) {
Debug.Log ("Got hit!");
m_HitTransform.position = UnityARMatrixOps.GetPosition (hitResult.worldTransform);
m_HitTransform.rotation = UnityARMatrixOps.GetRotation (hitResult.worldTransform);
Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z));
return true;
}
}
return false;
}
// Update is called once per frame
void Update () {
if (Input.touchCount ==3 && m_HitTransform != null)
{
var touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
var screenPosition = Camera.main.ScreenToViewportPoint(touch.position);
time += Time.deltaTime;
ARPoint point = new ARPoint {
x = screenPosition.x,
y = screenPosition.y
};
//Animation start
anim.SetBool ("IsCube,true");
if (time > life_time) {
gameObject.SetActive (true);
}
// prioritize reults types
ARHitTestResultType[] resultTypes = {
ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent,
// if you want to use infinite planes use this:
//ARHitTestResultType.ARHitTestResultTypeExistingPlane,
ARHitTestResultType.ARHitTestResultTypeHorizontalPlane,
ARHitTestResultType.ARHitTestResultTypeFeaturePoint
};
foreach (ARHitTestResultType resultType in resultTypes)
{
if (HitTestWithResultType (point, resultType))
{
return;
}
}
}
}
}
}
}
原因をご教示ください。
Answer by FlaSh-G · Jul 15, 2017 at 06:39 AM
Good thing you fixed the images, I think I understand your problem now. The animation overwrites the rotation you have set for each of the objects individually, so all your objects are in the same place. A solution to this would be to give each object a parent GameObject:
Create a new empty GameObject
Drag and drop the model onto that GO to make it its child
Copy the parent GameObject and rotate that instead of the actual model
The animation will then rotate relatively to the rotated parent.
Another thing that caught my eye is these lines:
if (Input.touchCount ==3 && m_HitTransform != null)
{
var touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
This cannot work properly. You basically expect the user to create three touches in the exact same frame. The touch with index 0 is the first touch, and it needs to be fresh (TouchPhase.Began) while the other two needed touches are already existing. Users will have a very low chance of actually triggering this.
== Original answer before added code and images ==
I cannot tell you where the problem is without seeing any code, but I guess it's one of these:
You're using the static keyword somewhere in your script without knowing what it does
You put the script controlling the parameter on one object only
If you post some code, I could probably edit this answer to something more precise.
Thanks your helping! I uploaded my code but im sorry if my code is hard to understand;( However i can answer any your question so pls help me
I couldnt.... I think i shouldnt duplicate object. I should make some (file).fbx and import them to Unity,no?
And sorry but this app is just demo application so its ok even if user maybe will not.I'll think UI later!
$$anonymous$$y answer assumes that your 3D model is already imported. What I proposed is a thing done in Unity itself, not the modelling program.
Do you know how to change the center point of object in Unity. I think we cant make animation which i need. I have to make the animation which is from bottom to the top.
If you know how to make this animation,pls tell me...
Your answer
Follow this Question
Related Questions
How to animate character with a prop? 0 Answers
How can I setup my bool/trigger in animator? 1 Answer
Adding new Animation to existing Animator not working correctly 0 Answers
Copy animation process from Animator of an object and paste it on the instantiated object of itself 0 Answers
Rig object offsets during animations 0 Answers