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
1
Question by PuzzleBox · Oct 31, 2011 at 08:57 PM · movementspeedchange

Change int value for 30 sec...

I've got AI script that moves forward at a set speed. I would like to have the AI to move forward at a faster speed for 30 sec when clicked by the mouse. How would I go about that? I would like to maintain this new speed for 30 seconds.

My Code:

 var speed = 6;
 var deer = 10;
 var tap = 100;
 var rotate;
 var target : Transform;
 var other : Transform;


 function OnMouseDown () {
     LevelController.Points += tap + 100;
     ChangeDirection();
 }
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

1 Reply

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

Answer by Julien-Lynge · Oct 31, 2011 at 09:02 PM

PuzzleBox,

I'm not going to read through the script you cut-and-pasted whole, so here's the pieces you'll need:

  • http://unity3d.com/support/documentation/ScriptReference/Input.GetMouseButtonDown.html

  • http://unity3d.com/support/documentation/ScriptReference/Coroutine.html

  • http://unity3d.com/support/documentation/ScriptReference/WaitForSeconds.html

Then:

var speedMultiplier = 1;

if (Input.GetMouse...) speedMultiplier = 2;

yield WaitForSeconds (30);

You can figure out the rest.

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 PuzzleBox · Oct 31, 2011 at 10:34 PM 0
Share

I tried adding "WaitForSeconds (30)" but it doesn't effect anything.

avatar image Julien-Lynge · Oct 31, 2011 at 10:40 PM 1
Share

You need to read the documentation that I included, which has examples of how to use the code examples I listed.

avatar image PuzzleBox · Oct 31, 2011 at 11:09 PM 0
Share

function On$$anonymous$$ouseDown () { LevelController.Points += tap + 100; speed += speed + 25; ChangeDirection(); yield WaitForSeconds (30); speed = 6; }

Here is what I found out from the Script Reference link you gave, still doesn't work.

avatar image Rod-Green · Oct 31, 2011 at 11:18 PM 2
Share

On$$anonymous$$ouseDown is not a coroutine. You need to start a new function that is a coroutine and have the action in that.. i.e.

   function On$$anonymous$$ouseDown()
   {
         StartCoroutine(SpeedUp());
   }

   function SpeedUp()
   {
         LevelController.Points += tap + 100;
         speed += speed + 25;
         ChangeDirection();
         yield WaitForSeconds (30);
         speed = 6; 
   }

http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$onoBehaviour.StartCoroutine.html?from=Coroutine

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

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

Error with CharacterMotor and unpausing 1 Answer

C# Twitchy Camera Movement 1 Answer

Making a moving gameobject approach and stop at a target (arrival behaviour) 0 Answers

Strange Rigidbody Behavior 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