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 sk3d · Nov 03, 2014 at 10:23 PM · move

Move many objects repeatdly

Hi,

In my scene I have 2 GameObjects, a seesaw that goes up and down and a gear that rotates, everyone with its own script with the move. I like to have a unique script that controls the time and move both launching it repetedly.

My problem is how to call GameObects and its own move scripts.

I have this now:

region variables

public float launchTime = 5f; // Time between moves. public float delay = 3f; // Delay time. #endregion

 void Start () {
     // Start calling the Move function repeatedly after a delay.
     InvokeRepeating("Move", delay, launchTime);
 }

 // Launch move scripts
 void Move()
 {        
     // I dont know how to implement ¿Maybe I catch objects with a Tag?
 }

Thank you

Comment
Add comment · Show 1
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 james_170482 · Nov 03, 2014 at 11:30 PM 0
Share

if i understand i would have a script like above with a repeating function and then call move in each gameobjects script. example untested

 public float launcheTime = 5f;
 public float delay = 3f;
 
 void Start()
 {
     InvokeRepeating( "$$anonymous$$oveAllObjects", delay, launchTime );
 }
 
 void $$anonymous$$oveAllObjects()
 {
     //Call the move function on gameobject 1
     //Call the move function on gameobject 2
     //Call the move function on gameobject 3
     //And so one
 }

example for calling scripts on another gameobject is found here

http://answers.unity3d.com/questions/7555/how-do-i-call-a-function-in-another-gameobjects-sc.html

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by reineinmyheart · Nov 05, 2014 at 01:10 PM

You would be doing something in this manner..

 public GameObject other_object;
 
 void Start()
 {
   other_object = GameObject.FindGameObjectWithTag("TagOfObject");
 }
 
 void Move()
 {
 
 other_object.GetComponent<NameOfScript>().function_name(); 
 //make sure the function you're calling is public
 
 }

but that only works if you're looking for one object. if however, you're going to call multiple objects with the same tag..you can do something like this..

 public GameObject[] other_objects;
 
 void Start()
 {
    other_objects = GameObject.FindGameObjectsWithTag("TagOfObject");
 }
 
 void MoveAllObjects()
 {
    foreach(GameObject other_object in other_objects)
    {
      other_object.GetComponent<ScriptName>().FunctionName();
    }
 }

Basically, you're storing each object in a list. Hope that helps. :D

Comment
Add comment · 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
0

Answer by bubzy · Nov 05, 2014 at 01:21 PM

Why not just have the movement code in each object? Then you can just have a public bool to reference to turn the movement on or off

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Simple move script 0 Answers

How Can I write a Click To Move Script? 2 Answers

move object! 0 Answers

how to make an object move around 3 Answers

Touch and move in any axis 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