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 Kitty · Mar 05, 2010 at 06:47 PM · toggle

Toggle Movement Help

I'm a little brain dead and should've been able to figure this out by now. So any help would be wonderful about now....

I'm trying to figure out the best way to script out a toggle using an input key like "m." Whenever the user presses the "m" on the keyboard, the motion of the gameobjects should start and then reset once pressed again.

I think could have it all in one code, but also know that I may to change it from an input key to use a GUI button. With that, I'd kinda like to have it in another script by itself. The code below is on the spheres....

var move : boolean; var speedOne : float; var speedTwo : float; var speedThree : float; var defaultRotation : Quaternion;

var switchTo = Transform;

function Start(){

 speedOne = Random.Range(50,200);
 speedTwo = Random.Range(50,200);
 speedThree = Random.Range(50,200);

 //Save Original/Default Rotation
 defaultRotation = transform.rotation;

}

function Update (){ if(move==true){ transform.Rotate(Vector3.right, speedOne*Time.deltaTime); transform.Rotate(Vector3.up, speedTwo*Time.deltaTime); transform.Rotate(Vector3.forward, speedThree*Time.deltaTime); } else{ transform.rotation = Quaternion.Slerp(transform.rotation, defaultRotation, Time.deltaTime); } move = GameObject.Find("Trigger").GetComponent.(Trigger),move; }

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
1
Best Answer

Answer by Eric5h5 · Mar 05, 2010 at 07:44 PM

This would be a good case for a static variable, where the "move" variable wouldn't be in that script at all, but in a separate manager script. You could have a script called Manager.js, attached to an empty game object:

static var move = false;

function Update () { if (Input.GetButtonDown("Move")) move = !move; }

Then your other script would check "Manager.move" instead of "move", and you would set up the "Move" button in the input manager. You can also have a GUI button function on the manager script that toggles "move" as well.

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 Kitty · Mar 05, 2010 at 08:07 PM 0
Share

Something like this?

GameObject.Find("00-Script").GetComponent("$$anonymous$$anager").move;

avatar image Eric5h5 · Mar 05, 2010 at 08:39 PM 0
Share

Actually no, with a static variable you don't have to use GetComponent, you can just use $$anonymous$$anager.move. You can do it with GetComponent if you're using a non-static variable, but I think static is appropriate in this case, since it's a global conditional.

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

No one has followed this question yet.

Related Questions

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

How to make gameObject and GUI button invisible/visible? 3 Answers

lighting click help 3 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 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