• 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
Question by Ochreous · Dec 20, 2014 at 05:03 AM · c#gameobjectrotate

C# Rotate More than Two GameObjects

I've been trying to figure out a way more than two gameobjects from RotatingGameObjects. i and i + 1 should go through RotatingGameObjects.length and move all those gameobjects accordingly. but for some reason it rotates only the first two gameobjects wit$$anonymous$$n RotatingGameObjects. Is there a hole in my logic?

 using UnityEngine;
 using System.Collections;
 
 public class RotateGameObjects : MonoBehaviour {
 public float fDistance = 1;
 public float fSpeed = 2;
 public float sensitivity = 3F;
 public GameObject[] RotatingGameObjects;
      
     void LateUpdate () {
      
         for(int i = 0; i < RotatingGameObjects.Length - 1; i++){
         RotatingGameObjects[i].transform.RotateAround(transform.position, Vector3.forward, - fSpeed / fDistance);
         RotatingGameObjects[i + 1].transform.RotateAround(transform.position, Vector3.back, - fSpeed / fDistance);
         }
     }
 }
Comment

People who like this

0 Show 4
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 EvilTak · Dec 20, 2014 at 05:06 AM 0
Share

What is the length of RotatingGameObjects?

avatar image Ochreous · Dec 20, 2014 at 05:23 PM 0
Share

It's four gameobjects.

avatar image EvilTak · Dec 20, 2014 at 05:28 PM 0
Share

Try placing a debug.log statement in the for loop. It should log 3 times. If it is, then your transforms are already at the required rotation, or the rotation can't be seen. If that isn't the case, then something else is wrong.

avatar image EvilTak · Dec 20, 2014 at 05:30 PM 0
Share

And also, I think you should use i += 2 instead of i++ in your for loop.

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by fafase · Dec 20, 2014 at 05:31 PM

  void LateUpdate () {
   
      for(int i = 0; i < RotatingGameObjects.Length - 1; i++){
          RotatingGameObjects[i].transform.RotateAround(transform.position, Vector3.forward, - fSpeed / fDistance);
          RotatingGameObjects[i + 1].transform.RotateAround(transform.position, Vector3.back, - fSpeed / fDistance);
      }
  }

I don't quite get the point here:

  1. you move the first guy forward and the second backward.

  2. you move the second forward (back to 0) and the t$$anonymous$$rd backward

  3. t$$anonymous$$rd goes forward (back to 0) and fourth move backward

As a result only the first and last are actually moving.

Comment

People who like this

0 Show 1 · 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 EvilTak · Dec 20, 2014 at 05:33 PM 0
Share

Thus see my latest comment ;)

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

26 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

Related Questions

C# Rotate GameObjects Regardless of List Size 2 Answers

C# Change Script Help 1 Answer

C# SetActive GameObject Array 2 Answers

C# GameObject Reverses Z Rotation 0 Answers

C# Throw GameObject Upon Mouse Click 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