Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 LukeThePunk666 · Dec 28, 2019 at 06:43 PM · spawninginstantiate prefabinstantiationenemys

How can I instantiate a unique game object?

Title says it all, I am working on a project that includes an enemy spawner on a timer. Every 15 seconds a new one should spawn. It does this but when a clone is spawned, the original becomes invulnerable and also deals no damage, the same follows with all the clones.

Is there a way to instantiate a completely unique game object with the health values etc completely specific to that one object?

Here's the code for the enemy spawner: public class RobotSpawner : MonoBehaviour { public float SpawnDelay; public float SpawnDelayMax = 15f; public GameObject Robot; public Transform Spawner;

     private void FixedUpdate()
     {
         SpawnDelay += Time.deltaTime;
         if(SpawnDelay >= SpawnDelayMax)
         {
             SpawnDelay = 0;
             Instantiate(Robot, Spawner);
         }
     }
 }

Am I being dumb, is this possible?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Twinklier · Dec 29, 2019 at 07:35 AM

What do you mean unique? Like having that entity have random health and whatnot? if so use Random.Range(min, max). So right at the spawning of that entity you change its health and whatnot to a random number.

also Time.deltaTime and Time.fixedDeltaTime has different values. And try not to use FixedUpdate in situation like this. It's better for your computer's health if you reserve that for physics calculations instead.

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 LOSTSOUL86 · Dec 29, 2019 at 10:04 AM

@LukeThePunk666 Yes it is possible. You just need to save "new" object as a prefab. Just create game object - Robot and drag it from the Hierarchy to the Resources folder) then it becomes a prefab then in the code you need to load it:

 prefabRobot = Resources.Load("Robot") as GameObject;
         if (prefabRobot == null)
         {
             Debug.LogError("Didn't find Robot");
         }

And then instantiate it always from this game object

  newRobot = Instantiate(prefabRobot) as GameObject;

Dont use prefabRobot gameobject in your game - it is just new object from which you always take copy copy.

You can also attach script to Robot that will set all values for you. It will be executed with each robot at the begining.

Comment
Add comment · 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 Twinklier · Dec 29, 2019 at 12:53 PM 0
Share

A prefab is like an original form where you look for to make a copy. It's created and stored in the asset folder. (Although Instantiate() doesn't always need prefabs, it would be a lot cleaner to do it this way)

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

121 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

Related Questions

How to spawn objects using an array of spawn points w/o intersecting 1 Answer

When the game starts, how can I instantiate a ball onto a random client? 0 Answers

Instantiated Bullets Not Picking Up Correct Position/Rotation 2 Answers

instantiate objects from right and left of screen to center 0 Answers

Why is it important to create an empty gameobject for my prefabs? 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