Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Corandy · Jun 21, 2011 at 07:35 PM · javascripttimefunctionduration

Giving a function time duration

Hi i'm know the little standarts of unity, but I have a difficulty with giving a function a duration. With this script I want to reveal a texture onscreen when I hit a target. But I have this problem on simmilar cases where I want to give a function a time duration. Sorry for my bad english. I hope the script shows what i want to have. If someone knows it, it helps me a lot with other pieces of the game. Lots of thanks in advance!

var collision: boolean = true;

var recovertime = 5;

function Update() {

var recover = recovertime - Time.time;

if (recover <= 0) { collision = true; } }

function OnControllerColliderHit (hit : ControllerColliderHit) {

if(hit.gameObject.tag == "enemy" & collision) {

     print("Au!");
     Script_Lives.LIVES -= 1;
     collision = false;
     recovertime = 5 + Time.time;
     var texture = GameObject.Find("Test");
     var script2 = texture.GetComponent("Script_ouch");
     script2.visible = true;

} }

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
2

Answer by flaviusxvii · Jun 21, 2011 at 08:00 PM

Choose a duration and then subtract Time.deltaTime on each call to Update(). Once you are down to zero then stop.

Easy peasy.

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 Corandy · Jun 21, 2011 at 08:20 PM

Oh I have made a terrible mistake, I thought that one was the easiest script to explain but with that script2.visible there is one what it makes difficult.

The one that maybe explain it truly is this one:

var boost: boolean = true; var boosttime = 5; var rentime = 2;

function Update () {

var recover = boosttime - Time.time; var rennen = rentime - Time.time;

if (recover <= 0) { boost = true; }

  if (Input.GetKey (KeyCode.LeftShift)&& boost)
  {   print ("Running!");
     var Karakter = GameObject.Find("Character");
     var script = Karakter.GetComponent("CharacterMotor");
     
     script.movement.maxForwardSpeed = 15;
     Camera.main.fieldOfView = 130;
     
     rentime = 2 + Time.time;
     
     if (rennen <= 0){
      print ("Not Running!");
      script.movement.maxForwardSpeed = 10;
      Camera.main.fieldOfView = 60;
      boost = false;
      boostime = 5 + Time.time;
      }
  }

}

Yes here I know what goes wrong, The timer to make the function happen works and that it triggers again after few seconds works. One thing that don't works is the duration of that function. I didn't understand exactly what your saying, but what do I wrong here? So sorry about that other question...

Let me explain, the boosttime triggers the event. when the event started it takes 2 seconds before it goes to the next event where he reset some stats. Is this the wrong way how I doing it or are there little mistakes?

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 flaviusxvii · Jun 21, 2011 at 08:29 PM 0
Share

"var $$anonymous$$arakter"

Uhhghghghh.. You shouldn't name your variables with upper case letters at the beginning. Reserve upper case for Classes (and possibly methods but I don't like that either).

Oh.. and this was probably an inappropriate "answer" to your question.

avatar image Corandy · Jun 21, 2011 at 08:34 PM 0
Share

No your right, that was not good grammar for program$$anonymous$$g, I have fixed that.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Time Function in Javascript? 1 Answer

How to make GUI Text appear after a certain amount of time 2 Answers

What is the best way to assign a duration to particles? 1 Answer

Subtract time from time 1 Answer

help with objexporter- passing parameters to C# function from JS 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