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 theafters3 · Dec 19, 2011 at 06:33 AM · teleporttimer countdown

teleporting player after time runs out

I'm something of a noob scripter so if the answer is obvious have mercy on me... I've been having trouble figuring out a way to teleport the player after a timer runs out. I've been trying it with this countdown script since there are objects you can collect to increase the time in my game and this makes that relatively easy, i just cant seem to get it to teleport the player. heres what i have so far

 var o_countdownTimer : countdownTimer;
 var f_timerdone = timerDone;
 var teleportTo : Transform;
 o_countdownTimer = GetComponent(countdownTimer);
 o_countdownTimer.setStartTime(10.0);
 o_countdownTimer.setTimerDoneAction(f_timerdone);
 o_countdownTimer.setTimerState(true);
 
 function timerDone() {
     transform.position=teleportTo.position;  
 }

in place of the first script on the link.

Thanks in advance! ^^

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 dannyskim · Dec 19, 2011 at 07:09 AM 2
Share

going to need more of your code to figure out what's going on here. You essentially just copy and pasted the code from that link and modified one line. You're setting the transform.position equal to teleportTo.position, and since teleportTo is declared as a Transform, there is no reason this shouldn't work.

You could be calling the function in the wrong place, not calling it at all, not setting objects in the scene correctly, etc.

2 Replies

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

Answer by theafters3 · Dec 19, 2011 at 09:03 AM

Thanks both but it turned out the GUItext it was attached too was teleporting, heres my solution if anyone needs it in the future xD

 var o_countdownTimer : countdownTimer;
 var f_timerdone = timerDone;
 var teleportTo : Transform;
 var teleportee : UnityEngine.GameObject;
 var vartime = 0;
 o_countdownTimer = GetComponent(countdownTimer);
 o_countdownTimer.setStartTime(vartime);
 o_countdownTimer.setTimerDoneAction(f_timerdone);
 o_countdownTimer.setTimerState(true);
 
 function timerDone() {
     teleportee.transform.position=teleportTo.position;      
 
     gameObject.active = false;
 }
Comment
Add comment · Show 2 · 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 syclamoth · Dec 19, 2011 at 09:04 AM 0
Share

Definitely facepalm material here.

avatar image theafters3 · Dec 19, 2011 at 09:15 AM 0
Share

indeed, indeed...

avatar image
1

Answer by fafase · Dec 19, 2011 at 07:22 AM

Mmm, maybe you have it but I dont see it, in the update you need to countdown a variable, varTime for example each frame and have a

var varTime = 100.0;

  if(varTime == 0)
     {
          transform.position = (0,0,0)
     }

Then you use a collision function to increment

 function OnControllerColliderHit(hit:ControllerColliderHit){
     if(hit.gameObject.tag == "itemTag")
     {
          varTime+=100;
          Destroy(hit.gameObject);
     }
 }

this function checks every frame if your player is colliding with the tagged item. You need to tag your item so that it matches what you write inside the brackets. In case you don't know about tagging, click on the object and on the top of the inspector there is a tag menu, click and choose a tag or edit new one. Then if the if statement returns true, your varTime gets 100 more and the item is destroyed so that the player cannot just recharge endlessly.

Hope that helps.

Comment
Add comment · Show 2 · 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 theafters3 · Dec 19, 2011 at 08:01 PM 0
Share

I would +1 you if it let me, even though this wasn't the exact answer it really really helped me a little bit later on. xD

avatar image fafase · Dec 21, 2011 at 11:53 AM 0
Share

You are now allowed to +1 if you wish. :).

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Script to teleport player (Beginner here) 0 Answers

Teleport Help. 2 Answers

how to add a sound to this script 3 Answers

Infinity Hallway 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