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 /
  • Help Room /
avatar image
0
Question by unity_QOya9nD58KG7cg · Feb 15, 2020 at 01:19 PM · renderingtimerdisableenabled

Im trying to create a crash bandicoot spin but how do i make it disabled after a second?

Im making a crash bandicoot game and im currently working on the spin mechanic and the spin works when the key is pressed but the renderer wont disable after the spin so it just keeps spinning! how do i get it to work? This is my script at the moment? Please help!

Script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class SpinStopper : MonoBehaviour {

 public double timer = 1;
 public GameObject SpinCB;
 public GameObject RealCB;

 void Update()
 {
     timer += Time.deltaTime;
     if(timer <= 0)
     {
         timer -= 0.5;
         SpinCB.SetActive(false);
         RealCB.SetActive(true);

     }
 }

}

Comment
Add comment · Show 2
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 JPhilipp · Feb 15, 2020 at 01:55 PM 0
Share

Where is your code that means to stop the script? And what do you intend to do with above-posted SpinStopper code? It looks almost as if your timer gets decreased infinitely, because you're saying "If it's equal-below zero, keep subtracting from it".

avatar image unity_QOya9nD58KG7cg JPhilipp · Feb 15, 2020 at 02:05 PM 0
Share

Im really new to scripting so im not that experienced! But what should i do to make it work?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Archelous · Feb 15, 2020 at 02:13 PM

How to count down is just subtract the time each frame took from the duration. Something like this.

      public float timer= 1;
      public GameObject SpinCB;
      public GameObject RealCB;
      void Update()
      {
           timer -= Time.deltaTime;
     
          if(timer <= 0)
          {             
              SpinCB.SetActive(false);
              RealCB.SetActive(true);
          }   
      }










Comment
Add comment · Show 5 · 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 unity_QOya9nD58KG7cg · Feb 15, 2020 at 02:21 PM 0
Share

How do i get it to reset when it reaches 0?

avatar image steven1022 unity_QOya9nD58KG7cg · Feb 15, 2020 at 02:44 PM 0
Share

reset your objects and timer to reset the situation

I would put your timer/action in a bool (like a spin button). when the bool is triggered (spin button hit) you want to set your spin to active and set your timer to 1. when your if statement kicks it will turn back to real and set your bool back to false and wait for the spin button to be hit again.

put a bool check on your spin button so that if your in a spin already you dont start a spin

     public float timer = 1;
     public GameObject SpinCB;
     public GameObject RealCB;
 
     public bool spinning;
 
     void Update()
     {
 
         if (spinning)
         {
             timer -= Time.deltaTime;
 
             //stop spinning when done
             if(timer <= 0)
             {
                 SpinCB.SetActive(false);
                 RealCB.SetActive(true);
                 spinning = false;
             }
         }
     }
 
     void SpinButton()
     {
         //make sure you arent spinning already
         if (!spinning)
         {
             //set up your spin
             timer = 1;
             SpinCB.SetActive(true);
             RealCB.SetActive(false);
             spinning = true;
 
         }
     }
avatar image unity_QOya9nD58KG7cg steven1022 · Feb 15, 2020 at 04:07 PM 0
Share

I still have a problem i dont know how to fix! As soon as i press play it starts to count down the spin timer then it goes all the way to -0.001279993 and stops there then nothing happens from that point forward? I want to be able to spin once everytime i press down "q" for a certain amount of time then it all resets and the spin model toggles off and the player model toggles back on with no problem? how do i fix that @steven1022 ? Please help me with this im so close to getting the mechanics finished!

Show more comments
avatar image
0

Answer by steven1022 · Feb 15, 2020 at 06:17 PM

This should be in your Update

         if (Input.GetKeyDown(KeyCode.Q))
         {
             SpinButton();
         }
Comment
Add comment · Show 1 · 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 unity_QOya9nD58KG7cg · Feb 15, 2020 at 06:54 PM 0
Share

I Finally got it to work thank you so much for the help!

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

223 People are following this question.

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

Related Questions

Slider Fill Area deactivate after jump 2 Answers

Selectively enable and disable Gamepads?,D 0 Answers

Disable player movement for some seconds? 0 Answers

How to stop a countdown timer and disable/stop everything in the scene? 1 Answer

Buttons: How to enable, disable and enable same button again? 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