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 carter-carl30 · Jul 10, 2016 at 03:42 PM · booleanscriptingproblemenabledactivation

hold button to stop spin then re-enable, script help

I have used this script I found on here http://answers.unity3d.com/questions/ask.html?space=8

I am making a slot machine.

i'm trying to make hold buttons to press and stop one of the 3 reels from spinning while the hold button is active.

this is my reel spinning scipt:

 #pragma strict
  var reel_1 : GameObject;
  var mySound: AudioClip;
  var ac : AnimationCurve;
  private var spinning = false;
  private var ray : Ray;
  private var rayCastHit : RaycastHit;
  
  function DoSpin(time : float, maxAngle : float) {
      spinning = true;
      var timer = 0.0;
      var startAngle = transform.eulerAngles.y;
  
      while (timer < time) {
          var angle = ac.Evaluate(timer/time) * maxAngle;
          reel_1.transform.eulerAngles = Vector3(angle + startAngle ,0.0,  90.0); 
          timer += Time.deltaTime;
          yield;
      }
      reel_1.transform.eulerAngles = Vector3(maxAngle + startAngle ,0.0,  90.0); 
      spinning = false;
  }
  
  function Update() {
       if(Input.GetMouseButtonDown(0)){
 
 ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 
 if (Physics.Raycast (ray, rayCastHit)){
 
 //add name of object/button to affect in ""
 if(rayCastHit.transform.name == "spin_button" && !spinning){
 
          DoSpin(3, 2160.0);
          //play sound
 //audio.clip = mySound;
 //audio.Play();
      }
  }
  }
  }

and this is my script for my hold button:

 private var ray : Ray;
 private var rayCastHit : RaycastHit;
 var mySound: AudioClip;
 var hold_lit : GameObject;
 var reel_1 : GameObject;
 var held : boolean;
 
 function Update(){
 
 if(Input.GetMouseButtonDown(0)){
 
 ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 
 if (Physics.Raycast (ray, rayCastHit)){
 
 //add name of object/button to affect in ""
 if(rayCastHit.transform.name == "hold_button_1"){
 
 held = !held;
 
 if(held){
 
 hold_lit.active = true;
 
 
 var varGameObject = gameObject.Find("reel_1");
 
 varGameObject.GetComponent(spin_script_reel_1).enabled = false;
 
 audio.PlayOneShot(mySound);
 
 reel_1.collider.enabled = false;
 
 }
 
 if(!held){
 
 hold_lit.active = false;
 
 var varGameObject1 = gameObject.Find("reel_1");
 
 varGameObject1.GetComponent(spin_script_reel_1).enabled = true;
 
 audio.PlayOneShot(mySound);
 
 reel_1.collider.enabled = true;
 }
 }
 }
 }
 }

When I press the hold button, It turns off my spin script (unticks it in the inspector) and when I spin the reels it stays as it should.

However, when I press hold button again it turns on the spin script (ticked in inspector) as it should, but when I press spin to spin the reels the previously held reel stays in place as if the script is not running.

Can anyone see the cause of this? please help it's driving me crazy lol :)

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

0 Replies

· Add your reply
  • Sort: 

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

61 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

Related Questions

Manual activation error - Hwid ulf can't be blank 0 Answers

Problems with debug and if-statement 1 Answer

How do I make a gun reload after 30 shots? 4 Answers

If statement not working 1 Answer

Get Time A Bool Has Been True 4 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