Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Evil-ProHack · Jul 24, 2020 at 11:07 AM · animationupdatemovement scriptstate-machinepositions

Script works with one gameObject but not works with other (update position)

I have a script that throw the arms to the player but only works with the right arm in the case of the left not work i do not know why with debbuging also cant see the error (In this case is not an animation problem without animation still not working)

 public class Boss2ArmAttackBehaviour : StateMachineBehaviour
 {
  
     Vector3 rightArmPos;
     Vector3 leftArmPos;
  
  
     public Transform leftArm;
     public Transform rightArm;
     public Transform rightArmB;
     public PlayerBehaviour player;
     public BossBehaviour2 boss;
     int rand;
     public float timer;
     public float minTime;
     public float maxTime;
     public float armSpeed;
     public Vector3 direction;
     public Animator animatorr;
     Transform rArm;
     Transform lArm;
     public Vector3 direction2;
     public  float timeToRecalculate;
     // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
     {
         animatorr = animator;
         timer = Random.Range(minTime, maxTime);
         animator.SetFloat("timelife", timer);
         //boss = GameObject.Find("Bossu2RealVariant(Clone)").GetComponent<BossBehaviour2>();      
         boss = GameObject.Find("Bossu2RealVariant").GetComponent<BossBehaviour2>();
         player = GameObject.Find("nave").GetComponent<PlayerBehaviour>();
         rArm = GameObject.Find("spaceParts_020").GetComponent<Transform>();
         rightArm = GameObject.Find("RightArm").GetComponent<Transform>();
         rightArmPos = rightArm.localPosition;
         lArm = GameObject.Find("spaceParts_019").GetComponent<Transform>();
         leftArm = GameObject.Find("LeftArm").GetComponent<Transform>();
         leftArmPos = leftArm.localPosition;
         // animator.SetBool("isAttackingWithArms", true);
         float lifetime = 0.3f;
         //TODO metodo para los dos brazos
         if (animator.GetBool("rightArm") == true)
         {
             StartRightArm();
             Debug.Log("r arm started");
         }
         if (animator.GetBool("leftArm") == true)
         {
         StartLeftArm();
  
             Debug.Log("l arm started");
  
         }
     }
  
  
     // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
     override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
     {
            CheckArm();
        
  
     }
     public void StartRightArm()
     {
  
      
         rightArm.localPosition = new Vector3(-1.655198f, -1.130143f, 0);
         Debug.Log(animatorr.GetParameter(0));
         //isAtackingWithRightArm = true;
         Debug.Log("posicion r" + rightArm.transform.position);
         Debug.Log("Espero que te llegue r");
         // animator.SetFloat("timelife", lifetime);
         rightArm.transform.position = rightArm.transform.position + direction * armSpeed;
         timeToRecalculate = Random.Range(2, 4);
         direction = player.transform.position - rightArm.transform.position;
         direction.Normalize();
  
     }
     public void StartLeftArm()
     {
  
      
         leftArm.localPosition = new Vector3(1.655198f, -1.130143f, 0);
         Debug.Log(animatorr.GetParameter(0));
         //isAtackingWithRightArm = true;
         Debug.Log("posicion l" + leftArm.transform.position);
         Debug.Log("Espero que te llegue l");
         // animatorr.SetFloat("timelife", lifetime);
         leftArm.transform.position = leftArm.transform.position + direction * armSpeed;
         timeToRecalculate = Random.Range(2, 4);
         direction = player.transform.position - leftArm.transform.position;
         direction.Normalize();
  
     }
     public void CheckArm()
     {
        // Debug.Log("timer" + timer + "tietorec" +timeToRecalculate);
         if (!PauseMenuBehaviour.isPaused && player.life >= 0)
         {
             if (timeToRecalculate <= 0)
             {
  
                 if (animatorr.GetBool("rightArm"))
                 {
                     direction2 = player.transform.position - rightArm.transform.position;
                     direction2.Normalize();
                     direction = direction2;
                     rightArm.transform.position = rightArm.transform.position + direction * armSpeed;
                     timeToRecalculate = Random.Range(2, 4);
                     Debug.Log("Direccion recalculada r");
  
                 }
                 else if (animatorr.GetBool("leftArm"))
                 {
                     direction2 = player.transform.position - leftArm.transform.position;
                     direction2.Normalize();
                     direction = direction2;
                     leftArm.transform.position = leftArm.transform.position + direction * armSpeed;
                     timeToRecalculate = Random.Range(2, 4);
                     Debug.Log("Direccion recalculada l");
  
                 }
  
             }
  
             if (timer <= 0)
             {
                 if (animatorr.GetBool("rightArm"))
                 {
                     Debug.Log("He esperado el timer r");
                     //    Destroy(rightArm.gameObject, lifetime);
                     // isAtackingWithRightArm = false;
                     rightArm.transform.rotation.Set(0, 0, 0, 0);
                     rightArm.localPosition = new Vector3(-1.655198f, -1.130143f, 0);
                     Debug.Log("Brazo r en su sitio");
                     animatorr.SetBool("rightArm", false);
                     animatorr.ResetTrigger("isAttackingWithRightArm");
                     if (animatorr.GetBool("phase2Trrigered") == false)
                     {
  
                         animatorr.SetTrigger("idle");
                         //                        animatorr.SetTrigger("phase2");
                         //                      animatorr.SetBool("phase2Trrigered", true);
                     }
                     else
                     {
                         animatorr.SetTrigger("phase2Idle");
                     }
                     //   rightArm.localPosition = new Vector3(-1.655198f, -1.130143f, 0);
  
                 }
                 else if (animatorr.GetBool("leftArm"))
                 {
                     Debug.Log("He esperado el timer l");
                     //    Destroy(rightArm.gameObject, lifetime);
                     // isAtackingWithRightArm = false;
                     leftArm.transform.rotation.Set(0, 0, 0, 0);
                     leftArm.localPosition = new Vector3(1.655198f, -1.130143f, 0);
                     Debug.Log("Brazo l en su sitio");
                     animatorr.SetBool("leftArm", false);
                     animatorr.ResetTrigger("isAttackingWithRightArm");
                     if (animatorr.GetBool("phase2Trrigered") == false)
                     {
  
                         animatorr.SetTrigger("idle");
                         //                        animatorr.SetTrigger("phase2");
                         //                      animatorr.SetBool("phase2Trrigered", true);
                     }
                     else
                     {
                         animatorr.SetTrigger("phase2Idle");
                     }
                     //   rightArm.localPosition = new Vector3(-1.655198f, -1.130143f, 0);
  
                 }
  
             }else
             {
                 if (animatorr.GetBool("rightArm"))
                 {
                     //TODO
                     //rArm.transform.Rotate(Vector3.back * armSpeed * Time.deltaTime);
                     //  rArm.transform.rotation = new Quaternion(rArm.transform.rotation.x,rArm.transform.rotation.y,rArm.transform.rotation.z + 1,100);
  
                     //rightArm.transform.Translate(Vector3.down * armSpeed * Time.deltaTime);
                     Debug.Log("this is update");
                     timer -= Time.deltaTime;
                     timeToRecalculate -= Time.deltaTime;
                     Debug.Log("Brazo en movimiento r");
                     // direction = player.transform.position - rightArm.transform.position;
                     direction.Normalize();
                     rightArm.transform.position = rightArm.transform.position + direction * armSpeed;
                     Debug.Log("");
  
                 }
                 else if (animatorr.GetBool("leftArm"))
                 {
                     //TODO
                     //lArm.transform.Rotate(Vector3.back * armSpeed * Time.deltaTime);
                     //  rArm.transform.rotation = new Quaternion(rArm.transform.rotation.x,rArm.transform.rotation.y,rArm.transform.rotation.z + 1,100);
  
                     //rightArm.transform.Translate(Vector3.down * armSpeed * Time.deltaTime);
                     Debug.Log("this is update");
                     timer -= Time.deltaTime;
                     timeToRecalculate -= Time.deltaTime;
                     Debug.Log("Brazo en movimiento l");
                     // direction = player.transform.position - rightArm.transform.position;
                     direction.Normalize();
                     leftArm.transform.position = leftArm.transform.position + direction * armSpeed;
  
                 }
  
             }
         }
     }
 }
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

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

Game broken after Unity 4.5.1 update 1 Answer

Should we check animation condition in Update or FixedUpdatE? 3 Answers

Parent and child repositioning 0 Answers

Handling Movement - Animations 1 Answer

Animator Boolean not Changing by script C# 1 Answer


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