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 Kurpowski86 · Mar 26, 2012 at 08:48 PM · objectsspawningmoving

Spawning objects from moving objects, In C#

Noob question. But i'm working on this project for class, a "kaboom" like game. Where as the top moving object, the computer(in this case it's also a UFO) spawns spheres(or bombs in this case) from it as it moves. The spheres fall to the bottom of the screen. You have to catch them with a platform. But all I want to know is how to spawn them from the UFO object. I looked up instantiate and prefabs, but am a little confused. Will appreciate any help. Thanks.

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 Berenger · Mar 26, 2012 at 08:54 PM

So, prefabs are assets in your project folder containing a gameObject and it's hierarchy you want to re-use. It's actually a GameObject saved on the computer.

Now, the Instantiate function can copy a GameObject, for example that prefab. So, in your UFO, add in your script and drag drop the Bomb prefab on the variable (in the inspector):

JS :

 var prefab : GameObject;
 
 function CreateBomb(){
     // That will copy the prefab into the scene at the UFO position
     // and without rotation, just as if you dragged it in
     // You don't have to affect it to a var, unless you need to.
     var bomb: GameObject = Instantiate( prefab,
                             transform.position, Quaternion.identity;
 }

C# (must be inside a class inheriting from MonoBehaviour:

 GameObject prefab;
 
 public void CreateBomb(){
     GameObject bomb = Instantiate( prefab,
                             transform.position, Quaternion.identity;
 }
Comment
Add comment · Show 3 · 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 Kurpowski86 · Mar 26, 2012 at 08:59 PM 0
Share

Thanks! I'm going to try that out. Is this C# or java? I'm using C# for this game.

avatar image Berenger · Mar 26, 2012 at 10:13 PM 0
Share

Good job, C# is the stuff ! I use js by default here though, as most beginners use it. I added the C# version, which isn't that different.

avatar image Kurpowski86 · Mar 26, 2012 at 10:17 PM 0
Share

Thanks for the help!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Massive amounts of objects. 0 Answers

Moving multiple objects independenty on mobile using touchscreen 2 Answers

Trouble "Spawning" Objects on client (UNET networking) 0 Answers

Destroy is not working with moving objects 1 Answer

Random object spawn? 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