• 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 WalaKauSaLoloKo · Jul 29, 2012 at 09:16 AM · game

How to move multiple objects one after the other??

and also i need to know how to randomly spawn that objects then move after the other..

Comment
Add comment · Show 2
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 Seth-Bergman · Jul 29, 2012 at 10:08 AM 2
Share

search google: "unity how to move objects" and "unity how to spawn objects". You will find countless examples. You may want to start with some basic tutorials, this is a good list:

http://answers.unity3d.com/questions/12321/How-can-I-start-learning-Unity-fast--List-Of-Tutorials-.html

avatar image WalaKauSaLoloKo · Jul 29, 2012 at 12:43 PM 0
Share

sir i have already done moving one object.. my problem is.. i want to move the second object after the 1st object finish moving and destroyed. then after 2nd then 3rd... and so on... then i also want to randomly spawn those objects... im working a game called HOLE IN THE WALL.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Seth-Bergman · Jul 29, 2012 at 12:56 PM

ok, I'll bite

let's say you have a var for the current object to move:

 var myObject : GameObject;

then your code for movement could be for example (in the Update function):

 if(Input.GetKey("w"))
 myObject.transform.Translate(Vector3.forward);

...etc

also in the Update function:

 if(!myObject){   //myObject is null, replace it
 
 var randomVector3 = Vector3(Random.Range(-100,100),0,Random.Range(-100,100));
 
 myObject = Instantiate(myPrefab,randomVector3,Quaternion.identity);
 
 }

that should get you started

EDIT: ok, here goes:

 using UnityEngine;
 
 using System.Collections;
 
 public class Cushion : MonoBehaviour {
 
 public float Speed = 5;
 private GameObject myObject;
 public GameObject myPrefab;
 
 void Update () {
 
     float amtToMove = Speed * Time.deltaTime;
 
     if(!myObject){
     Vector3 randomVector3 = new Vector3(Random.Range(-10,10),0,Random.Range(-10,10));
     myObject = Instantiate(myPrefab,randomVector3,Quaternion.identity) as GameObject;
     }
     else{
     myObject.transform.Translate(Vector3.up * amtToMove);
 
 
 
    if (myObject.transform.position.y > 50)
 
     {
       //myObject.transform.position = new Vector3(Random.Range(-2, 2), transform.position.y, -1f);
       // not much point to changing the position, if you're going to destroy it
       Destroy(myObject);
        }
     }
 
 }
 
 }

my c# is rusty I THINK that should work.. make sure to turn your cube into a prefab, and drop the prefab into the slot "myPrefab" in the inspector

Comment
Add comment · Show 14 · 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 WalaKauSaLoloKo · Jul 29, 2012 at 03:57 PM 0
Share

sir that "myobject" is the name of my object? thank very much for your reply sir... i put a script in my firstbox (Box01).... this is my code:

using UnityEngine;

using System.Collections;

public class Cushion : $$anonymous$$onoBehaviour {

 public float Speed = 5;


void Update () {

     float amtTo$$anonymous$$ove = Speed * Time.deltaTime;

     transform.Translate(Vector3.up * amtTo$$anonymous$$ove);



    if (transform.position.z < -171)

     {
       transform.position = new Vector3(Random.Range(-2, 2), transform.position.y, -1f);

       Destroy(this.gameObject);
 
     }

}

}

avatar image WalaKauSaLoloKo · Jul 29, 2012 at 04:01 PM 0
Share

i put also the same script on my 2nd box... and of course they will move both at the same time... i don't know how to move the 2nd box.... after the 1stbox destroyed.... again sir i appreciate your help... thank you...

avatar image Seth-Bergman · Jul 29, 2012 at 04:22 PM 0
Share

see above edit.. this will create a new box when the old one dies

avatar image WalaKauSaLoloKo · Jul 30, 2012 at 03:27 AM 0
Share

sir there is an error in script... this line.. myObject =Instantiate(myPrefab,randomVector3,Quaternion.identity); it says there that "cant implicitly convert type Unity.Engine.Object to Unity.Engine.GameObject. an implicitly conversion exist(are you missing a cast?)" .... i put a printscreen of my project below sir...

avatar image WalaKauSaLoloKo · Jul 30, 2012 at 03:30 AM 0
Share

for the print screen sir... my objects was imported and created using 3d max studio.. thank you for your help again sir... sorry im so new here in unity >.

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

6 People are following this question.

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

Related Questions

getting udp package info inside unity (GlovePIE) 0 Answers

Time limit on my game with selection menu 0 Answers

thrid person help 1 Answer

GUI Texture not showing in Game 1 Answer

i need help trying to build game 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