• 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 remvan3d · Jul 27, 2010 at 12:36 PM · delayrespawnonceonly

How to make my espawn delay trigger to work more than once.

I put this question up on the unity forum, but got so many different answers that I didn't know what to do. Tried out all of them but none seemed to work like I wanted. Some of them even did so that the script did not work. So I therefor they here since I have had more luck here before.

I have this respawn script that is supposed to delay the player repawn action by 5 seconds after passing -3 in the Y-axis. It is a diving game and so the point is to let the 5 seconds to show the score and so on before respawning back on the diving board. My problem is that the 5 second delay only works once. After the second jump of the board and the player hits -3 in the y-axis the player respawnes emediatly. I therefore need to make the script work everytime. I need the respawn action to be delayed everytime and not just once. Can someone help me please?

I have only been working with scripts for about a month now and I am still pretty wet behind the ears when it comes to unity script.

This is my code atm:

var reSpawnPoint: Transform; var timer : float = 0.0;

function Update ()

{ if(gameObject.transform.position.y < -3){ timer += Time.deltaTime; if(timer>5) gameObject.transform.position = reSpawnPoint.position;

} }

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 sovalopivia · Jul 27, 2010 at 01:28 PM 0
Share

In case that is how your code is formatted within your editor, and not just how you typed it up here; I would recommend utilising indenting and brackets for all if statements, it is easier to read.

See how $$anonymous$$ike did it below. :)

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Mike 3 · Jul 27, 2010 at 12:45 PM

Just need to reset the timer variable to 0:

var reSpawnPoint: Transform; var timer : float = 0.0;

function Update () { if(gameObject.transform.position.y < -3) { timer += Time.deltaTime; if(timer>5) { timer = 0; gameObject.transform.position = reSpawnPoint.position; } } }

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 remvan3d · Jul 28, 2010 at 10:21 AM

Thanks a bunch!

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

No one has followed this question yet.

Related Questions

Fade on death! 1 Answer

How do you make a respawn and checkpoint script? 0 Answers

Shoot only once when clicked 1 Answer

How do I make a character die when he fells. 1 Answer

My respawn system does not work 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges