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 /
This question was closed Jul 10, 2019 at 05:22 PM by beverbende for the following reason:

was my own mistake in a stupid code error

avatar image
0
Question by beverbende · Jul 10, 2019 at 02:58 PM · prefabprefab-instanceprefab changing at runtime

Changing the variable 'power' of ONE turret instead of ALL turrets

The example is simplified: if i click on a certain spot in my scene, a turret should spawn which is a prefab. (this goes well) i do this with Instaniate(turretprefab, coordinates, quaternion.identity);

The turret is a prefab with a script attached which instantiates the variable (in the start method) power = 0; when i click on a turret, the power should increase by 1. (this goes well) however when i create another turret and press on this turret, it has the same value of the first turret that was instantiated.

How can this be fixed? i want both turrets to have seperate variables instead of sharing the same value. meaning clicking on turret 1 a 100 times should give this turret power = 100. and clicking on turret2 twice should give it power = 2.

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 Hellium · Jul 10, 2019 at 04:08 PM 0
Share

Please, edit your question and provide your current script.


Your issue could be caused by a variable declared static. In this case, you have to remove the static keyword.

1 Reply

  • Sort: 
avatar image
0

Answer by I_Am_Err00r · Jul 10, 2019 at 04:02 PM

It might be located in the script that you have the power increases with, without seeing it I couldn't tell you for sure if that is the issue, but I've had trouble with instantiating objects in my projects in the past and avoid it all costs; I usually create the object in the scene, set it to inactive, then when I need to "instantiate" it I just set the object to active and move it's position to wherever I would need it.

Regardless of what is causing the error, you should consider object pooling rather than instantiating; it usually offers better control over the objects individually and is much better on performance.

Here is an excellent online tutor going over the exact subject, his stuff is usually pretty legit and I've learned a ton from Brackey's, but I haven't watched this particular video: https://www.youtube.com/watch?v=tdSmKaJvCoA

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

Follow this Question

Answers Answers and Comments

141 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 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 hide a character prefab 1 Answer

How can I switch between prefab variants in runtime. 1 Answer

Prefabs instantiated at runtime disappear right after 0 Answers

Prefabs spawn with wrong values 0 Answers

Prefabs won't change? 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