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 zillion · Oct 14, 2012 at 12:15 PM · javascriptspawninvoke

A small spawning challenge..

I'm currently creating a script that allows me to spawn objects from a gameobject. The script will spawn the objects by instantiating them, and then adding a force to their rigidbody to create movement. To call their method, I am using the Invoke method in the start function. I have 5 of these gameobjects, each with the same script. And as you can understand, if I use Invoke("Object1", 1), it will invoke this function on ALL 5 of my game objects. I do not want this, and I somehow want to make it that it will choose a random one of these gameobjects to invoke the function from. Or if that is far to advanced, to maybe somehow tell it which gameobject to make it spawn from. Would the best idea be to make this script single, say spawnScript1, spawnScript2, so on so on, and attach it to each of the gameObjects, and to Invoke the functions from each of the single scripts? Or is there a better way of doing this by keeping the 1 script? Thank you!

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 MountDoomTeam · Oct 14, 2012 at 02:21 PM 0
Share

O$$anonymous$$... You are Using the Answers System Wrong, someone will give you $$anonymous$$us points for doing that ... unless it an answer to you question, use a Comment!

If you have 5 functions on 5 gameobjects, all the same style, why bother have them on diff objects? instantiate spawn and give them constantforce doesnt sound like very radically different code you have to put in a seperate code fucntion?

have a rest and do something else and try again abit later, it's just a case of doing 5 different tasks by a random variable. the acess path and organistaion is written online or its for you to read about.

5 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Montraydavis · Oct 14, 2012 at 01:07 PM

You don't need to Invoke. When assigning a script to the object, they work independently for the most part . . .

Use SendMessage ( ) instead.

 var ScriptName : Component ;
 ScriptName = .......GetComponent ( ScriptName ) ;
 ScriptName.SendMessage ( "FunctionName", {params} );
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 zillion · Oct 14, 2012 at 01:12 PM

Hmmm SendMessage is quite cost effective, since this game is based around the iPhone. Any other suggestions?

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 MountDoomTeam · Oct 14, 2012 at 01:15 PM

you should attach some code of the core lines that you are referring to.

Also using paragraphs is great when you're talking about something so complicated!

It sounds like you are going through quite a lot of complicated stuff to invoke five functions to instantiate things at different times. You don't really have to use the invoke function, I expect it is better suited to tasks like making a door close five seconds after you open it.

I would do something like this:

just set the five game objects as variables in the script that are supposed to invoke their method.for example drag them onto the Inspectoror call them by name in the script. afterwards trigger one of each randomly :

 var ST = spawn trigger: int = random.range (0,5);
 trigger spawn trigger to run when you need to invoke a random object's method
 
 if (ST ==0) {get gameobject 1's compenent script, trigger it's method.}
 etc up to ST=4
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 zillion · Oct 14, 2012 at 01:18 PM

Hmmm I think I understand haha. And yeah, I've been trying to put it into paragraphs, yet for some reason, each time I try to put a break between my sentences with the enter key, it posts without it?

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 zillion · Oct 14, 2012 at 01:25 PM

I lied @ZoomDomain , I'm still super confused!

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

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

11 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

Related Questions

GetComponentInChildren(Renderer).active wont work? 2 Answers

How to add a peaking system? 1 Answer

script linking 1 Answer

problem at adding script 1 Answer

How do I get my "dashing" animation to work? 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