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 RashidBekar · Sep 09, 2012 at 01:11 PM · collisioninstantiateprefabtrigger

Instantiated Prefab's script doesn't work

Didn't anyone have this problem? Please help i moved to udk just because of this problem. But udk is really hard to understand for me.

I have a prefab and a script attached to it. When i instantiate prefab in runtime with code the script doesn't work properly. But when i just put the prefab in the scene without code everything works fine.

Below script is attached to a cube that is where i want the prefab's instantiate position

 public static var notarray: Array;
 var timearray: Array;
 public static var i=0;
 
 //i drag the prefab here in inspector view
 var ob: Transform;
 
 function Start () {
 notarray=new Array();
 timearray=new Array();
 
 notarray.Add(ob);
 timearray.Add(0);
 notarray.Add(ob);
 timearray.Add(1);
 notarray.Add(ob);
 timearray.Add(1);
 notarray.Add(ob);
 timearray.Add(1);
 
 while(notarray.length>i){
 yield WaitForSeconds(timearray[i]);
 Instantiate(notarray[i],transform.position,transform.rotation);
 i++;
 
 }
 
 
 }

/// This question is edited because i understood there wont be any answers, maybe this time?

Comment
Add comment · Show 3
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 hvilela · Oct 06, 2012 at 03:03 PM 0
Share

Please, define: "The script doesn't work properly".

avatar image KiraSensei · Oct 06, 2012 at 03:19 PM 0
Share

Why your var i is declared as static ?

avatar image RashidBekar · Oct 06, 2012 at 05:11 PM 0
Share

hvilela--- i control collision in script with on trigger enter then in update function i control what will happen when in trigger, everything works fine if i just drug the prefab to the scene, but if i instantiate it in game collision codes doesnt work properly-- with properly i mean this: This is a guitar hero game, notes come and you press the key, when a long note comes it is supposed to don't disappear untill the user don't do it wrong but it disappear if i instantiate prefab in runtime. another example: some other prefab even doesn't do anything, nothing works with the script.

The only reason that the script doesnt work is that i instantiate it in runtime. Why i want to do this in runtime? Because i need to put the notes in specific positions as you can see above i have a yield Wait for Second method that waits for the time that is in the timearray.

$$anonymous$$iraSensei: Does it matter? I made it because maybe i want to reach it from other scripts.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by RashidBekar · Oct 06, 2012 at 08:13 PM

I solved the problem. I can't tell how because i did a lot of things. Maybe later, i can explain it in here. So the others have this problem can solve it too..

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 BFips · Oct 23, 2016 at 03:40 PM 0
Share

Any idea about what was wrong?

avatar image
0
Wiki

Answer by haico1992 · Oct 06, 2012 at 05:03 PM

Maybe you just need to put those code in to a new function other than Update() and Start(), since it have "yield";

Here what I do: Make a script with a public variable :Transform;

Attach that script to any object in scene, Main camera for example.

Drag the prefab you want to instantiate to the variable.

Instantiate those prefab in that script.

 function YourCode()
 {
   Doing Stuff  
 }
 
 function Start(){
   YourCode();
 }
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 RashidBekar · Oct 06, 2012 at 05:34 PM 0
Share

didn't work; It is the same thing at all

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

12 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

Related Questions

Prevent instantiating on collider 1 Answer

Scripts of instantiated objects 1 Answer

Trigger between 2 kinematic bodies not firing? -1 Answers

Instantiate A Prefab 1 Answer

Instantiated Prefab Trigger not firing. 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