• 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 andez · Feb 05, 2014 at 08:19 PM · mathf.clamp

stuck on how to apply Mathf.Clamp c#

,c# mathf.clamp, Sorry about being another pesky noob to all this, but I really do need help I have this very basic code that been messing round with but I can't for the life of me figure out how to place mathf.clamp to it tried so many ways but to no avail, if any one could help me out and possibly tell me what the the best way forward is just can't get past this

any help no matter how small even a step in the right direction would be amazing ,

thanks again , ANDY ( here is my code )

 using UnityEngine;
 using System.Collections;
 
 public class lower : MonoBehaviour 
 {    public GameObject Cylinder;
     public Texture2D lower1;
     public Texture2D lower2;
     public float  LowerTiming = 10.0f;
     private Transform move;
 
 
     void Start () 
     {
         guiTexture.texture = lower1;
         move = Cylinder.GetComponent<Transform >();
     }
         void Update () 
     {
       foreach (Touch touch in Input.touches) 
     {
       if (guiTexture.HitTest(touch.position) && touch.phase ==TouchPhase.Began)
        {
           guiTexture.texture = lower2;
                 
         move.transform.Rotate (Vector3.down * ( LowerTiming * Time.smoothDeltaTime));
                             
        }
               
     if (guiTexture.HitTest(touch.position) && touch.phase == TouchPhase.Stationary)
        {
           guiTexture.texture = lower2;
 
     move.transform.Rotate (Vector3.down * ( LowerTiming * Time.smoothDeltaTime));
                 
        }
     if (guiTexture.HitTest(touch.position) && touch.phase==TouchPhase.Moved)
             {
             guiTexture.texture = lower1;
             }
     else if (guiTexture.HitTest(touch.position) && touch.phase == TouchPhase.Ended)
             {
             guiTexture.texture = lower1;
             }
         }
     }
 }
 
  
                
       
Comment
Add comment · Show 4
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 Eowyn27 · Feb 05, 2014 at 09:25 PM 1
Share

Why do you want to apply $$anonymous$$athf.Clamp? Is there a specific reason you need to use it?

avatar image andez · Feb 06, 2014 at 07:13 AM 0
Share

Sorry should of said it is to stop the rotation of an artillery This code is for the downward movement

avatar image giano574 · Feb 06, 2014 at 09:42 AM 1
Share

It is very difficult to help when it is unclear what your intentions are. What exactly do you wish to acomplish? If you wish to stop the rotation, when?

avatar image andez · Feb 06, 2014 at 11:59 AM 0
Share

I am wanting to clamp on the x and y rotation for the up , down , left , right vector3's .this code is just for the vector3.down (-1f,0f,0f) ,sorry if I am not clear enough. As it is for a artillery , I am wanting it to not drop below 90° and for my vector3.up not more than 30° off vertical (resting rotation is horizontal 90°), hope this helps at all

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Two Clamps on the Same axis 1 Answer

eliminating angular velocity when clamp value hit? 0 Answers

Clamp rotation of object with C# on mobile. 1 Answer

helps to adapt the Mathf.Clamp in c #! 1 Answer

Mathf.Clamp Problem with Character Controller Script 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