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 SupremeRussian · Feb 22, 2014 at 08:43 AM · transformprefabbooleantaginstances

Transform All Instances Of A Prefab

Hey guys, this problem has bugged me for hours now. You see, I have a "Loot" prefab which drops loot when an enemy dies. When I perform an action, I set the "lootMove" variable to true. Here it is basically:

if(lootMove == true)

 transform.LookAt(Vector3(target.position.x, target.position.y, target.position.z));
 myTransform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);

Now all would be fine and dandy, but here is my problem. Let me first show you my variables:

 var target : Transform;
 
 var moveSpeed = 3;
 
 var rotationSpeed = 3;
 
 var myTransform : Transform;
 
 var lootMove : boolean = false;

Now here is the killer:

 function Awake()
 {
 
 myTransform = GameObject.FindWithTag("Loot").transform;
 
 }

You see all the variables work fine with me, but the myTransform variable just doesn't seem to work. Whatever I put it as not all instances of the prefab go to the spot I want them too. It is either one of them, or none. To sum up, I want a way to set myTransform to a value that will make ALL of the instances of my "loot" prefab go to my spot. Here is what I have tried:

 myTransform = GameObject.FindGameObjectWithTag("Loot")
 myTransform = GameObject.FindGameObjectWithTag("Loot").transform

I also tried countless other things, but I got too lazy. Again, to make myself clear, I would like a value to set myTransform to that would make all instances of my "loot" prefab follow my transform script back at the top. Thank you :).

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 POLYGAMe · Feb 22, 2014 at 09:08 AM

The transform will only be set to one instance of transform with the tag loot. You can't assign multiple transforms to one transform, you're only setting it to a single one. You'll need to use arrays. Basically your transform translate code will only move whatever you set myTransform to. I'm guessing it will be the first instance of a loot tagged transform that Unity finds.

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 SupremeRussian · Feb 22, 2014 at 09:24 PM 0
Share

Arrays, hmmm, thank POLYGA$$anonymous$$e. I will take a look into that. :)

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

20 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

Related Questions

Grab position from instantiated object 1 Answer

Assign a 'Transform' target to prefab by finding a 'GameObject' 1 Answer

Distance from tagged objects problem 1 Answer

(Unity 2D C#) Move instantiated prefab on Y axis? 1 Answer

Spawn Shield to all objects 2 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