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 colsonenderby · Jul 18, 2011 at 05:58 AM · guispeed upboost

I need Help With a Speed up script

I want my character to have a speed up boost when ever he inputs left shift but it only lasts for a few seconds and cant be used again for 10 seconds. There is also a Gui texture that is supposed to appear when its ready to be used.

Here is the script i used but the Gui texture does not work right.

var speed= 40.0; var rotateSpeed = 3.0; var runningSpeed= 10.0; var strafeSpeed = 40; var savedTime=0; var GUI1 : GUITexture;

function Update () {

     var seconds : int = Time.time;
     var oddeven = (seconds % 2);
         
     if(oddeven)
     {
         Shoot(seconds);
     }

}

function Start(){ GUI1.enabled = false; }

function Shoot(seconds){

     GUI1.enabled = true;

if (Input.GetKey("left shift")){ if(seconds!=savedTime){ var controller : CharacterController = GetComponent(CharacterController); //transform.Rotate(0, Input.GetAxis ("Horizontal") rotateSpeed, 0); var forward = transform.TransformDirection(Vector3.forward); var curSpeed = speed Input.GetAxis ("Vertical"); controller.SimpleMove(forward * curSpeed); } } }

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 GuyTidhar · Jul 18, 2011 at 06:30 AM 0
Share

Please make sure you format all code snippets using the button labeled: "101010"

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GuyTidhar · Jul 18, 2011 at 06:29 AM

Here is an option:

 var speed : float = 40.0; 
 var rotateSpeed : float = 3.0; 
 var runningSpeed : float = 10.0; 
 var strafeSpeed : float = 40; 
 var GUI1 : GUITexture;
 
 var speedUpTime : float = 5; // How long do you have a speed boost
 var speedUpFactor : float = 1;
 var controller : CharacterController; 
 
 function Start()
 { 
     controller = GetComponent(CharacterController); 
      GUI1.enabled = true; 
 }
 
 function Update () 
 {
     if ( GUI1.enabled && Input.GetKey("left shift") )
     {
         StartCoroutine(EnableShiftAfterAWhile());
         StartCoroutine(SpeedUpForAWhile());
     }
 
     // Put here you movement processing
     transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0); 
     var forward = transform.TransformDirection(Vector3.forward); 
     // You current speed should be effected by the speedFactor
     var curSpeed = speed * Input.GetAxis ("Vertical") * speedUpFactor; 
     controller.SimpleMove(forward * curSpeed); 
 }
 
 function SpeedUpForAWhile()
 {
     speedUpFactor = 2; // Move twice as fast
 
     yield WaitForSeconds(speedUpTime);
 
     speedUpFactor = 1; // Regular move speed
 }
 
 function EnableShiftAfterAWhile()
 {
     GUI1.enabled = false;
 
     yield WaitForSeconds(10);
 
     // Once the time wait time has passed you can re-enable the gui (and shift...)
 
     GUI1.enabled = true;
 }


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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

What is frame, How OnGuI is called every frame? 2 Answers

'MouseLook.sensitivityX' is inaccessible due to its protection level. 2 Answers

What can i use besides an event current 1 Answer

What Am I Doing Wrong? Variable Names 3 Answers

Gui Counter wont count up at all 0 Answers


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