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 MC HALO · Apr 30, 2011 at 05:26 AM · mousemove

Can some one explain this script to me :)

Hello guys can you please explain this script to me if it is possible i would like if you could add comments in on each line telling why they are called and what they do :). This is the mouse move script by the way :). Thank you in advance here is the script :

using UnityEngine; using System.Collections;

public class MoseMoveY : MonoBehaviour {

 public enum RotationAxes { MouseY = 2 } // ??

 public RotationAxes axes = RotationAxes.MouseY ;  // ?? 

 public float sensitivityY = 15F;

 public float minimumY = -360F;

 public float maximumY = 360F;



 Quaternion originalRotation; // ??

 void Update ()
 {
     if (axes == RotationAxes.MouseY )// ??
     {

         rotationY -= Input.GetAxis("Mouse Y") * sensitivityY * Time.deltaTime;// ??

         rotationY = ClampAngle (rotationY, minimumY, maximumY);// ??


         Quaternion YQuaternion = Quaternion.AngleAxis (rotationY, Vector3.right);// ??


         transform.localRotation = originalRotation * YQuaternion ;// ??
     }



 }

 void Start ()
 {

     if (rigidbody)// ??
         rigidbody.freezeRotation = true;// ??
     originalRotation = transform.localRotation;// ??
 }

 public static float ClampAngle (float angle, float min, float max)// ??
 {
     if (angle < -360F)// ??
         angle += 360F;// ??
     if (angle > 360F)// ??
         angle -= 360F;// ??
     return Mathf.Clamp (angle, min, max);// ??
 }

}

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 ina · Apr 30, 2011 at 05:42 AM

See my pastebin @ http://pastebin.com/Zzh6NwPc for easy reading

using UnityEngine;
using System.Collections;

public class MoseMoveY : MonoBehaviour {

public enum RotationAxes { MouseY = 2 } // define the enum later referenced as RotationAxes.MouseY

public RotationAxes axes = RotationAxes.MouseY ; // there are 2 axes, defined by line above

public float sensitivityY = 15F;

public float minimumY = -360F;

public float maximumY = 360F;

Quaternion originalRotation; // originalRotation is defined as a quaternion. quaternions are useful for expressing rotations.

void Update () { if (axes == RotationAxes.MouseY ) {

     rotationY -= Input.GetAxis("Mouse Y") * sensitivityY * Time.deltaTime;// rotation is defined by the y mouse position multiplied by sensitivity, set it to motion by multiplying it with deltaTime

     rotationY = ClampAngle (rotationY, minimumY, maximumY);// limit angle using ClampAngle defined below


     Quaternion YQuaternion = Quaternion.AngleAxis (rotationY, Vector3.right);// define YQuaternion


     transform.localRotation = originalRotation * YQuaternion ;// manually convert originalRotation to localRotation
 }



}

void Start () {

 if (rigidbody)// if object is rigidbody
     rigidbody.freezeRotation = true;// then we prevent it from rotating
 originalRotation = transform.localRotation;// the originalRotation is the localRotation, when the script starts

}

public static float ClampAngle (float angle, float min, float max)// ?? { if (angle < -360F)// angle += 360F;// if the angle is less than -360 degrees, keep incrementing it by 360 until we get back to within boundaries. these angles are all the same if (angle > 360F)// if the angle is more than 360 degrees, keep decreasing it by 360 until we get within boundaries. again, these are all the same, as there are only 360 degrees in a circle, and 720, and -360 are the same 0 degrees angle -= 360F; return Mathf.Clamp (angle, min, max);// limit angle between min and max }

}

Comment
Add comment · Show 1 · 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 MC HALO · Apr 30, 2011 at 05:50 AM 0
Share

thank you very much :)

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

accessing a variable from one script in another with Unity 1 Answer

Unity 3D Audio Clip Disabled 1 Answer

Basic scripting help (FPS Tutorial) 1 Answer

how to collide .fbx animation in unity 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