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 Moose54 · Jun 23, 2014 at 05:27 PM · collisiongameobjectrigidbodyshootingwaitforseconds

How to delay time reset on collision?

Standard delay time 2 second.but I launch the rocket when it hits an object, I want to restart delay.

How can this be?

alt text

 #pragma strict
 var rockettt : GameObject;
 var readynow : boolean = true;
 function Update () {
 
     if(readynow){
         MakeBox();
         
     }
 }
 
 
     function MakeBox () {
         
         if (Input.GetButton ("FireLazer")) {
         readynow=false;
         Instantiate(rockettt, Vector3(transform.position.x , transform.position.y + 1,0), Quaternion.identity );
         yield WaitForSeconds (2);
         readynow=true;
           }
           }
     
           
           
      
  
 


helpp.jpg (88.8 kB)
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
0
Best Answer

Answer by jefjohms · Jun 24, 2014 at 01:44 AM

Instead of doing WaitForSecond() which can not be changed, I would track time manually so you can choose to reset when box collider fires.

 public float maxShotTime;
 public float currentShotTime;
 
 void Start(){
  maxShotTime = 2.0f;
  currentShotTime = 0.0f;
 }
 
 void MakeBox(){
 currentShotTime += Time.DeltaTime;
 if (currentShotTime > maxShotTime){
  //instantiate your rocket
 }

In your script for the rocket prefab reset the time to maxShotTime in collisionEnter function.

 public GameObject fireControlObject; //object your previous script is attached
 
 void OnCollisionEnter(Collider other){
 //here you can differentiate what it hit if needed
 yourScriptFilename script = fireControlObject.GetComponent<yourScriptFilename>();
 script.currentShotTime = script.maxShotTime;
 
 //now you can destroy the rocket object
 }


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 Moose54 · Jun 24, 2014 at 07:30 AM 0
Share

gives this error.

An embedded statement may not be a declaration or labeled statement

alt text

hata.jpg (41.3 kB)
avatar image Moose54 · Jun 24, 2014 at 10:02 AM 0
Share

I've tried a little and done with your help.thank you very much ! :)

avatar image
0

Answer by doghell · Jun 23, 2014 at 07:48 PM

Why don't you just keep Input.GetButton in the Update() function, make it run MakeBox(), and check for the "readynow" in the MakeBox() function itself.

if you detect a collision, you can just set the public readynow value to true

 function Update () {
 
     if (Input.GetKeyDown(KeyCode.L)) {
         MakeBox();
     }
 }
 
 
 function MakeBox () {
     if (readynow) {
         readynow = false;
             Instantiate(rockettt, Vector3(transform.position.x , transform.position.y + 1,0), Quaternion.identity );
         yield WaitForSeconds (2);
         readynow=true;
     }
 }
 
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 Moose54 · Jun 23, 2014 at 08:14 PM 0
Share

but I can not write collision into the function :S

avatar image doghell · Jun 24, 2014 at 12:42 AM 0
Share

in the OnCollisionEnter() function for the projectile (rockettt), you should just set the gun's readynow variable to true. http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html

avatar image Moose54 · Jun 24, 2014 at 07:36 AM 0
Share

If I write into projectile,this time of the rocket does not recognize the term readynow

avatar image doghell · Jun 24, 2014 at 06:18 PM 0
Share

yea, you can access the public variables and functions of another object/script via theGameObject.Find or GetComponent methods (as described by jefjohms)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Dragging object out of position 2 Answers

Problem with collision - Collision.other.gameObject is obsolete 1 Answer

Audio.PlayOneSHot won't work? 0 Answers

My rigidbody is floating away, its a child of a parent 0 Answers

ai help: fire shots 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