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 HumanError · Dec 07, 2012 at 07:02 PM · tagspawning

Remmember from where it spawned.

I made some helicopters which spawns whenever another helicopter is destroyed. The helicopter follow me from above and when its run out of ammo it should fly back exactly to where it spawned. For this, I put a tag on some objects which can spawn them.

the problem is that when the helicopter spawns it can't choose the object that spawned it because i got many of them. The code works fine when I got only one object that can spawn helicopters.

What should I do to make the helicopter remmember from where it spawned?

Edit: Now I have these codes: on the helicopter:

 var landingPlate;
 
 function SetSpawner (spawner : GameObject)
 {
    landingPlate = spawner.transform.position;
 }

The line for the distance is in the Update function.

On the spawner:

 var spawnHelicopter = Instantiate (helicopter, spawnPoint.transform.position, Quaternion.identity);
 spawnHelicopter.SendMessage ("SetSpawner", this);

I get this error after some changes (the codes above are the codes I have now): NullReferenceException: Object reference not set to an instance of an object.

What is the problem?

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 HumanError · Dec 12, 2012 at 12:31 PM 0
Share

Up, I need an answer, I can't continue to build my game without it.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by DannyB · Dec 07, 2012 at 07:50 PM

You could do this:

After the Spawner spawns the Helicopter, it will send a message to it:

 helicopter.SendMessage( "SetSpawner", this );

Now, the Helicopter object will have a method that can accept this message, and will use it to remember the position of the spawner locally, in the helicopter:

 public void SetSpawner( GameObject spawner ) {
     originPosition = spawner.transform.position;
 }
Comment
Add comment · Show 10 · 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 HumanError · Dec 08, 2012 at 07:35 AM 0
Share

I use JS, not C#. I think the first code you gave me works on JS, the second code you gave me I need to change to:

function SetSpawner (spawner)

and the rest of it looks the same?

avatar image DannyB · Dec 08, 2012 at 08:05 AM 0
Share

Yes, I believe so, perhaps:

function SetSpawner( spawner : GameObject )
or
function SetSpawner( spawner : Spawner )

I believe both should work

See http://docs.unity3d.com/Documentation/ScriptReference/GameObject.Send$$anonymous$$essage.html

avatar image HumanError · Dec 08, 2012 at 02:36 PM 0
Share

Ok, I'll try it.

avatar image HumanError · Dec 09, 2012 at 02:30 PM 0
Share

The code works but now the helicopter don't know the distance between it and the spawner. This is importent because the helicopter's movement based on the distance from the spawner (flys up until it gets to the proper hight to fly forward).

Sorry for bad english.

avatar image DannyB · Dec 10, 2012 at 12:16 PM 1
Share

What exactly doesn't work? Do you get an error? Are you sure the object spawner is valid?

spawner should be a global variable in your helicopter script.

Show more comments

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

10 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

Related Questions

Spawning random prefabs with the same tag 2 Answers

How do i make an object spawn another one? 1 Answer

Spawning in a specified location 2 Answers

Remmember the spawner 2 Answers

problem with set tag in unity network 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