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 TheFrankman123 · Apr 16, 2012 at 03:31 PM · ontriggerenterrespawntranform.position

Moving a gameObject to the position of an empty gameObject

I am exporting to flash and reloading the level when you die takes too much time. So, i am just moving the player back to the beginning point when you die.

I hard coded the position to send the player but that way i would have to re-write the script for each level to match the beginning points. So i am trying to save the position as a private variable.

So i have an empty game object at the beginning point of the level and when the player is in a situation that would cause death he moves to that position. However, there are different erros when i try different things. Below is the code i am using and i'll put the error up for the currently problem with this attempt.

 #pragma strict
 var enableGUI : boolean = false;
 private var respawnPoint : Transform; 
 
 function Start () {
 
  respawnPoint = gameObject.FindWithTag("respawnPoint").transform;    
     
 }
 function OnTriggerEnter (hitPlayer : Collider) {
     
     
     
     if(hitPlayer.gameObject.tag == "Player") {
 
         enableGUI = true;
         Time.timeScale = 0;
         hitPlayer.transform.position = Vector3(respawnPoint.transform.position.x, respawnPoint.transform.position.y, respawnPoint.transform.position.z);
         
     }        
 }

I am getting Null Exception Reference... but not to sure why since i have set the variable in start...

HELP! Frustrating.

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
Best Answer

Answer by yusufulutas · Apr 16, 2012 at 03:39 PM

You try respawnPoint = GameObject.FindWithTag("respawnPoint").transform; not gameObject, true is GameObject; and check tag.

Comment
Add comment · Show 4 · 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 TheFrankman123 · Apr 16, 2012 at 03:47 PM 0
Share

Still getting the Null Exception on the 'respawnPoint =' and also the same error on the line 'hitPlayer.transform.position.

avatar image TheFrankman123 · Apr 16, 2012 at 03:48 PM 0
Share

Sorry, don't worry i was being a tit. Forgot to add the actually tag onto the respawnPoint game object. Thank you though.

avatar image yusufulutas · Apr 16, 2012 at 03:51 PM 0
Share

okay, you check again tag and check case sensitivity. you try hitPlayer.gameObject.transform.position

avatar image yusufulutas · Apr 16, 2012 at 03:52 PM 0
Share

okay, no problem :)

avatar image
1

Answer by TheFrankman123 · Apr 16, 2012 at 04:52 PM

For future reference if anyone google searches this there is a better/easier way to do this:

You can just do it as:

 function OnTriggerEnter (hitPlayer : Collider) {
 
 
 
     if(hitPlayer.gameObject.tag == "Player") {
 
        hitPlayer.transform.position = respawnPoint.transform.position;
 }
 
 }

Instead of defining all the axis separately.

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

OnTriggerEnter forcefield help! 1 Answer

Respawning a player after a certain amount of time 0 Answers

[solved] respawn when destroyed 1 Answer

How to make object move smoothly. 3 Answers

Trouble with a respawn script 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