• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kiyoshi35 · Jul 15, 2017 at 05:55 AM · animationanimatorblenderboolduplicate

Blenderで作成したオブジェクトをUnityで正常に再生する方法

Blenderでアニメーション付きのオブジェクトを作成しました。

そのオブジェクトをDuplicateで複数作成させた後に、Unityの実行ボタンを押すと正常に全てのオブジェクトのアニメーションが再生されます。 alt text しかし、アニメーションの再生のタイミングを制御するために、Animatorで一度Emptyを通してboolで条件定義をさせると、一つのオブジェクトのアニメーションしか再生されません。 alt text

<コード内容>

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;
                     }
                 }
             }
         }
     }

 
 }

}

原因をご教示ください。

スクリーンショット-2017-07-15-141452.png (427.6 kB)
スクリーンショット-2017-07-15-141406.png (484.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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:

  1. Create a new empty GameObject

  2. Drag and drop the model onto that GO to make it its child

  3. 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.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kiyoshi35 · Jul 15, 2017 at 06:58 AM 0
Share

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

avatar image FlaSh-G · Jul 15, 2017 at 08:00 AM 0
Share

I updated my answer.

avatar image Kiyoshi35 FlaSh-G · Jul 15, 2017 at 09:35 AM 0
Share

I appreciate it. I'm checking now

avatar image Kiyoshi35 FlaSh-G · Jul 15, 2017 at 12:02 PM 0
Share

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!

avatar image FlaSh-G FlaSh-G · Jul 15, 2017 at 01:08 PM 0
Share

$$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.

avatar image Kiyoshi35 FlaSh-G · Jul 15, 2017 at 03:14 PM 0
Share

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

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

178 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rig object offsets during animations 0 Answers

Add a bool to animator & activate by key press 1 Answer

Animation From blender to Unity Animator - Import Error 1 Answer

Armature changes position when game starts 2 Answers

Mecanim : is it possible to use the same Generic animations on multiple objects sharing the same skeleton ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges