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
0
Question by latsushi · Mar 08, 2013 at 08:03 PM · slidershakemainmenu

Horizontal Slider

I'm trying to implement a slider in the Main Menu that adjusts the degree to which the camera shakes. The menu has a Play Game, Quit, and slider.

Here's my code for the slider:

 using UnityEngine;
 using System.Collections;
 
 public class Shaky_Slider : MonoBehaviour {
     
     public float hSliderValue = 0.0f;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     
     void OnGUI()
     {
         hSliderValue = GUI.HorizontalSlider(new Rect(525, 980, 200, 30), hSliderValue, 0.0f, 10.0f);
 
         if (hSliderValue == 0.0f)
         {
         iTween.ShakeRotation(gameObject,iTween.Hash("x", 0.0f,"y", 0.0f,"looptype",iTween.LoopType.none,"delay",0.0f,"time",0.0f));    
         }
         if (hSliderValue > 0.0f && hSliderValue < 1.0f)
         {
         iTween.ShakeRotation(gameObject,iTween.Hash("x", 0.1f,"y", 0.05f,"looptype",iTween.LoopType.none,"delay",0.0f,"time",0.0f));
         }
         if (hSliderValue >= 1.0f && hSliderValue < 2.0f)
         {
         iTween.ShakeRotation(gameObject,iTween.Hash("x", 0.2f,"y", 0.1f,"looptype",iTween.LoopType.none,"delay",0.0f,"time",0.0f));
         }
         if (hSliderValue >= 2.0f && hSliderValue < 3.0f)
         {
         iTween.ShakeRotation(gameObject,iTween.Hash("x", 0.3f,"y", 0.3f,"looptype",iTween.LoopType.none,"delay",0.0f,"time",0.0f));
         }
         if (hSliderValue >= 3.0f && hSliderValue < 4.0f)
         {
         iTween.ShakeRotation(gameObject,iTween.Hash("x", 0.4f,"y", 0.5f,"looptype",iTween.LoopType.none,"delay",0.0f,"time",0.0f));
         }
         if (hSliderValue >= 4.0f && hSliderValue < 5.0f)
         {
         iTween.ShakeRotation(gameObject,iTween.Hash("x", 0.5f,"y", 0.9f,"looptype",iTween.LoopType.none,"delay",0.0f,"time",0.0f));
         }
         if (hSliderValue >= 5.0f && hSliderValue < 6.0f)
         {
         iTween.ShakeRotation(gameObject,iTween.Hash("x", 0.6f,"y", 1.3f,"looptype",iTween.LoopType.none,"delay",0.0f,"time",0.0f));
         }
         if (hSliderValue >= 6.0f && hSliderValue < 7.0f)
         {
         iTween.ShakeRotation(gameObject,iTween.Hash("x", 0.7f,"y", 1.7f,"looptype",iTween.LoopType.none,"delay",0.0f,"time",0.0f));
         }
         if (hSliderValue >= 7.0f && hSliderValue < 8.0f)
         {
         iTween.ShakeRotation(gameObject,iTween.Hash("x", 0.8f,"y", 2.1f,"looptype",iTween.LoopType.none,"delay",0.0f,"time",0.0f));
         }
         if (hSliderValue >= 8.0f && hSliderValue < 9.0f)
         {
         iTween.ShakeRotation(gameObject,iTween.Hash("x", 0.9f,"y", 2.5f,"looptype",iTween.LoopType.none,"delay",0.0f,"time",0.0f));
         }
         if (hSliderValue >= 9.0f && hSliderValue <= 10.0f)
         {
         iTween.ShakeRotation(gameObject,iTween.Hash("x", 1.0f,"y", 2.9f,"looptype",iTween.LoopType.none,"delay",0.0f,"time",0.0f));
         }
     }
 }

When I adjust the bar in the menu, the camera changes its degree of shakiness accordingly. However, the problem is that the camera shakes in the menu scene. What do I have to do so that the camera shakes in the scene. Right now, I have the script on the Main Camera in the menu scene.

Any assistance is appreciated. Thank you for your time.

Comment
Add comment · Show 5
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 latsushi · Mar 08, 2013 at 08:06 PM 0
Share

I should note that when I play game, it loads the scene that I want the camera to shake in. Again, thank you for your time.

avatar image Kleptomaniac · Mar 09, 2013 at 07:19 AM 0
Share

Can you not just use different cameras for the menu and your main game scene, and disable and enable each one accordingly?

Also, why not just link your HorizontalSlider values directly to the x and y changes in the iTween.ShakeRotation call, as opposed to having the long chain of if statements that you have right now?

avatar image latsushi · Mar 09, 2013 at 10:47 PM 0
Share

@robertbu You're right that I don't want it to shake in the menu but do want it to shake in the main scene. However, right now it's shaking in the menu and I want it to shake in the main scene. How do I do that?

avatar image Kleptomaniac · Mar 09, 2013 at 11:08 PM 0
Share

Did you see my comment?

avatar image latsushi · Mar 09, 2013 at 11:31 PM 0
Share

@$$anonymous$$leptomaniac Regarding putting the HorrizontalSlider directly to the x and y changes: we just altered the code for the iTween.ShakeRotation so we can disregard that part. I saw your comment.I do have different cameras for the menu and the main game scene.

$$anonymous$$y camera in the main scene is called 'Camera' and it's tagged '$$anonymous$$ainCamera'

$$anonymous$$y camera in the menu is called '$$anonymous$$ainCamera' and it's tagged '$$anonymous$$ainCamera'

With this information, could you please help guide me as to how I would disable the '$$anonymous$$ainCamera' in the menu and enable the 'Camera' in the main scene.

I imagine I can put the code I need into the spot that says to load the main scene when the player clicks 'Play Game'

I know this is a lot of information. I appreciate any help @$$anonymous$$leptomaniac.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kleptomaniac · Mar 09, 2013 at 11:45 PM

Ah, after reading your question a few more times, I think I've finally got it.

The reason that this is happening is because you have two cameras, and you are changing the ShakeRotation on the camera you don't want to change.

All you need to do is create an object reference to your scene camera: public GameObject sceneCam; and then change your ShakeRotation calls so that instead of saying iTween.ShakeRotation(gameObject, etc.), you say iTween.ShakeRotation(sceneCam, etc.)

That should work. :)

Klep

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

11 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

Related Questions

Changing two different objects renderer colour 1 Answer

Options Menu with volume sliders accessible from Main Menu scene and Game scene 2 Answers

I can not figure out The referenced script on this Behaviour (Game Object 'MainMenu') is missing 1 Answer

Multiplayer - Other players shaking back and fourth on moving platform 2 Answers

iTween - Increase shake over time? 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