• 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 Nelyan · Feb 09, 2015 at 07:35 PM · listrespawnpickupspawnpoints

Retrieve the exact spawn point when I destroy its pickup

Hi everyone I have a little problem here, I have already checked here and on google but nothing seems to help to solve my problem so here we are, I have a list of spawn points

 spawnPointList = new List<SpawnPoint>();

and I have 3 classes (pickup controller, spawn point and player controller).

Inside the class pickup controller I instantiate for every spawn point a pickup and i set the availability as false:

 void Start()
     {
         //spawn the first pickups on every spawnPoint and after set them unavailable
         foreach (SpawnPoint spawn in spawnPointList) 
         {
             SpawnPickup(spawn.GetID());
             spawn.available = false;
         }
     }

As you can see I have an ID for every spawn point (3 spawn point at the moment).

Inside the Player controller I check if I collided with a pick up and from the same function i set some needed data in the pickup controller:

 void OnControllerColliderHit (ControllerColliderHit hit)
     {
         if (hit.gameObject.tag == "Pickup")
         {
             Pickup_controller.collision = true;
             Pickup_controller.object_hit = hit.gameObject;
         }
     }

After that, in the pickup controller update, I call the function that destroy the pickup:

 void Update()
     {
         SpawnPoint spawn = spawnPointList.Find (x => x);
         //on collision with a pick up we destroy it and spawn another one on that spawn point after a while
         if (Pickup_controller.collision == true) 
         {
             //this is the function that delete the pick up
             Collected(Pickup_controller.object_hit);
 
             time -= (Time.deltaTime / Time.deltaTime);
             if (spawn.available == true)
             {
                 if(time < 0)
                 {
                     SpawnPickup(spawn.GetID());
                     spawn.Availability(false);
                 }
             }
         }
     }

Well now the problem is: I can't just disable the pickup to enable it back later, I really have to destroy it and place another NEW one in the empty spawn point but from here I don't know how to retrieve the empty spawn point after i destroy the pick up.

Already tried to save the pickup in another Game object calling the delete function delete the copy too.

The problem isn't the pickup (because in the future I have to take the pickup and put into inventory so have to left the scene) the problem is how to retrieve the exact empty spawn point in the list after i destroy "its" pick up.

I create a public ID component for every spawn point thinking it might come in handy.

Thank you in advance.

PS.: Right now (clearly) in the pickup controller update function after the delete of the pickup, and after a while, a new pickup is spawned on the empty spawn point but doesn't work because after the start function in pickup controller the availability remain false.

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 AcE_fLoOdEr · Feb 10, 2015 at 04:45 AM 0
Share

Can I suggest something?

Why don't you get the X,Y,Z co-ordinates when you destroy the object after its picked up, then when it's time to spawn another one, use those exact same co-ordinates to place the newly spawned object? Just an idea.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by team_eden · Feb 10, 2015 at 05:08 AM

You can set the pickup to enabled again, it just has to be done from a separate object. Each time you create an object to be disabled, register it with a higher up parent, and when it needs to be enabled again, signal it through the parent.

Then it is simply a matter of

 parent.childSpawn[x].enabled=true; // childSpawn is a variable of type scriptComponent you wish to set

To get the proper spawn point, you must have the object you pickup 'send' its 'spawn point' back to the controller. I have just implemented this in my project. You need to study more about utilizing your variables on Instantiation. Right when you spawn something, boom, you should be setting the parent into the object being spawned. Then when its time, the object sends its parent back to the controller as a variable within a function, boom, gone.

Your answers lie within, good luck

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 Nelyan · Feb 10, 2015 at 12:10 PM

I already did a thing like parenting the pickup with its spawnpoint:

public void SpawnPickup(int id){

             //the number of spawn points in the list
             numberOfSpawnPoints = spawnPointList.Count;
         
         //if the number of pickup are higher then number of spawn point the number of pickup will be the exact number of spawn point
         if (Pickup_controller.instance.numberOfPickups > numberOfSpawnPoints)
         {
             numberOfPickups = numberOfSpawnPoints;
 
         }
 
         //retrieve the position of the pickup spawn point
         Vector3 spawnedPickupPosition = spawnPointList.Find (x => x.IdTrue(id)).transform.position;
         Quaternion spawnedPickupRotation = spawnPointList.Find (x => x.IdTrue(id)).transform.rotation;
 
         //instatiate the pickup with the above postion and rotation
         GameObject spawnedPickup = GameObject.Instantiate(instance.pickup_prefab, spawnedPickupPosition, spawnedPickupRotation) as GameObject;
         
         spawnedPickup.transform.parent = instance.spawnPointList.Find (x => x.IdTrue(id)).transform;
     }

But I call this function in the "start" to spawn the first pickups then I call it again in the update, clearly this function (SpawnPickup) spawn a pickup on a spawnpoint, so I don't know how to retrieve the empty spawnpoint also if I have parented every single pickups to every single spawnpoint, I mean you said to "send" its "spawnpoint" back to the controller, ok, but from the piece of code above can you tell me what is missing to save this data somewhere?

When the game start I spawn not the original pickup but its clones, so every spawnpoint have a clone of the pickup, after that as I said before i don't want (if possible) to enable the pickups and disable them when i "interact" with them and enbale again after a while, i need to destroy the pickup, it need to left the scene completly.

Thank you for the answer probably this is the solution :)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Respawning gameobject not working c# 0 Answers

Why doesnt my respawn script work? 2 Answers

A respawn script for enemies. 1 Answer

Respawn player at different Spawnpoints 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