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 sandhillceltic · Jun 07, 2013 at 05:32 PM · spawnwaitforsecondscreating

How do I spawn another object at the position of another?

I am making a horror game that spawns the ghosts behind the player. I have a ghost prefab, and I want it to spawn behind the player when it is called by this script-

 var spawn : Transform;            //the object that will spawn that causes the scare
 var howoften : int = 10;    //how often a scare will occur (lower numbers=more freq scares)
 private var randomnum = 0;     //the random number that is generated
 var maxtimewait = 10;            //max time between scares
 
 while (true) {                     
 
     yield WaitForSeconds(Random.Range(maxtimewait, 0));
     
     randomnum = Random.Range(howoften, 0);
     
     if(randomnum < 1) {
         audio.Play();             //this is where I would put the spawning function, but I used audio instead to make sure the rest of the script was working
     }
 }


Can someone help me with a line of script that will spawn the ghost (var spawn) at the location of the spawn cube (have not added that var yet)..

-Thanks

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
1

Answer by moghes · Jun 10, 2013 at 10:43 PM

Well if you have this script attached to your player, then it goes like this

 var spawn : Transform;            
 var howoften : int = 10;    
 private var randomnum = 0;    
 var maxtimewait = 10; 

 // newly added variables  
 var pPos: Vector3; // your player position
 var ghostPos : Vector3;
 var yourGhost : GameObject;
 var distance : float = 1;
  
 while (true) {                     
  
     yield WaitForSeconds(Random.Range(maxtimewait, 0));
  
     randomnum = Random.Range(howoften, 0);
  
     if(randomnum < 1) 
     {
          pPos= this.transform.position; // get your player position
          ghostPos = Vector3(pPos.x , pPos.y , pPos.z - distance);
           
          Instantiate(yourGhost , ghostPos , Quaternion.identity);
       
     }
 }


Note that you have to drag you ghost prefab to your yourGhost variable and set a distance value as you wish. I have set a default to be 1 unit.

Comment
Add comment · Show 5 · 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 sandhillceltic · Jun 11, 2013 at 02:53 PM 0
Share

This script is spawning a ghost at single position...$$anonymous$$y goal is making the ghost spawn at the same coords as another gameobject, no matter if the object moves..thanks for the help though, Its a real start :)

-cheers

avatar image sandhillceltic · Jun 11, 2013 at 02:55 PM 0
Share

Actually, I got it working...thanks again, I will reply to tell you if I had change anything, but I shouldnt (it looks good!)

avatar image moghes · Jul 17, 2013 at 07:18 AM 1
Share

@sandhillceltic , well if the answer did help you, please just set it as true, by clicking on the tick

avatar image sandhillceltic · Jul 17, 2013 at 06:00 PM 0
Share

Thanks! I upvoted the answer, as it fixed my problem! Totally forgot that!

avatar image moghes · Aug 26, 2013 at 07:51 AM 0
Share

@sandhillceltic thanks for the upvote, but that does not set the answer as true, any user can see a green icon even before opening the page if the answer is set as true, while he sees a blue icon meaning no correct answer yet.

The icon is locatated below the upvote and downvote icons, its the tick sigh.

avatar image
0

Answer by Seizure · Jun 07, 2013 at 08:50 PM

clone = Instantiate (spawn, transform.position, transform.rotation);

Object.Instantiate

Comment
Add comment · Show 2 · 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 sandhillceltic · Jun 10, 2013 at 10:28 PM 0
Share

Could you please put it in the code, so I can see how I would use it? Thanks

avatar image moghes · Jun 10, 2013 at 10:34 PM 0
Share

Do you have this script attached to your player?

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

16 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Can anybody help me fix this wave spawning script please? 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Material doesn't have a color property '_Color' 4 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