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 The CADfather · Dec 16, 2014 at 07:49 PM · spawn points

Trying to get a prefab to pop up at various spawn points

Hi. I'm completely new to Unity and sort of making it up as I go along. I've managed to stumble through all the problems I've had so far (mostly thanks to this forum), but this one has me completely stumped - mostly because it's so close to working, but there's a glitch that doesn't make sense to me.

I'm creating a top-down maze style game where 'collectables' appear at randomly selected spawn points. I've created a prefab of the collectable (called 'Conversation'), then created prefabs of all the possible spawn points (just as empty gameobjects), and then I've created a list with all this spawn points in. Next I've got the following code in a script called ConversationStarter which is attached to the player.

     public GameObject[] availableSpawns
     public GameObject Conversation;
     private GameObject Spawn;;
 
     // Use this for initialization
     void Start () {
         ChangeSpawn();
         StartConversation();
     }
 
     // Select random spawn point from list and create it
     public void ChangeSpawn() {
         int randomSpawnIndex = Random.Range(0, availableSpawns.Length);
         GameObject SpawnPoint = (GameObject)Instantiate(availableSpawns[randomSpawnIndex]);
     }
 
     // Create conversation prefab and locate at spawn point
     public void StartConversation(){
         Spawn = GameObject.FindWithTag ("Respawn");
         Instantiate(Conversation,Spawn.transform.position,Spawn.transform.rotation);

This is supposed to pick a spawn point from the list as soon as the game starts and then instantiate the conversation prefab at that location. At this point it works fine, but the next bit is where it's gone weird.

In a second script (also attached to the player) I've got the following:

     void OnTriggerEnter2D(Collider2D collider) {
         if (collider.gameObject.CompareTag("Conversation"))
             Listening(collider);
     }
 
     // When reaching conversation, add point, destroy conversation and spawn point, then create another
     void Listening(Collider2D pointsCollider) {
         points++;
         Destroy (GameObject.FindWithTag ("Respawn"));
         Destroy (pointsCollider.gameObject);
         GetComponent<ConversationStarter>().ChangeSpawn();
         GetComponent<ConversationStarter>().StartConversation();
     }
 

With this I was trying to make it that when the player reaches the location, the conversation and the spawn point are destroyed and then the original subroutine runs again to select a new spawn point and instantiate the conversation again. And I thought I'd cracked it with this.

Unfortunately, when the player reaches it and they disappear, the conversation reappears for an instant in the same spot (therefore giving an unnecessary second point) before going to the second place. On top of this, the spawn point jumps to the second location, and from then on the two are out of sync.

Running the game frame by frame, there seems to be a single frame where the spawn point is at location 2, but in the next frame it jumps to location 3, whilst the conversation is now at 2.

Any ideas what I've done wrong?

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Create GameObject On Click Not Working 0 Answers

Trying to use lists to check for available spawn points 2 Answers

Spawn multiple enemies from spawn point 4 Answers

Spawn system not working correctly 1 Answer

How to Set a cut off point where I cant click on my object 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