Unity Learning Notes

Source: Internet
Author: User



MonoDevelopGarbled problem

This problem has been a long time for dad....

UnityBring your OwnMonoDevelopThe project view on my Computer (Win7has been garbled, project name, Project tree, and file name all display Solutionkeys box, today, the font changed to the default fontConsolas, the unintentional insertion of willow solves this problem....

See picture


AboutUnitySome of the concepts and syntax

I've been using my spare time lately to seeUnityOfAPI, look relatively thin but the actual operation of the relatively few, yesterday there is a full day of free time, coupled with a good idea, want to realize it, because the model used is not complex, do not need to use the modeling software, and do not go around to engage in material, stickers on the collection of pictures from the collected to do some screening and cutting work, Everything seemed to be easy to fix, so I started writing code. I am from the basicGUIStart writing, landing box, main menu, which is the basic way to enter the game, and thenNEW GAMEEnter the first level of the game, where the show is just beginning.

I spent a lot of time picking out stickers and experimenting with differentShaderOn, these are not the focus, when I write to the user input character detection when dumbfounded, I inUnity AnswerSome of the code above, there are loadingSystem.regularexpression (Loading part of the extra code, and I want to try to keep the size of the game to a minimum)And then do it with regular expressions.Replace, there are relatively simple character comparisons, withEvent.current.characterwith character' A ', ' Z ', ' a ', ' z ', ' 0 ', ' 9 'For comparison, which is inC #The code in theUnityscriptwill be prompted not toStringType is converted intoCharType, the problem is more involved. SinceUnityscriptWon't putStringAutomatically converted intoChar, then I'm going to convert it manually? But the basic types of methodsUnityIn the documentation

Basically not mentioned, thenUnityHow to deal with itString,char,arrayThese basic types of?


Here are some key concepts to clarify.UnityThree scripts are available for our use,C#,jsAndBoo,JavaScriptProgrammers may feel that usingJSIt will be handy, but don't be fooled by appearances. This oneJSAnd we are familiar withECMAVersionJSThere's a big difference, that's why I'm inclined to call itUntyscriptInstead ofJavaScriptThe reason that it didn'tJSNo type declaration, no object direct amount and function direct amount, noprototypeThe inheritance mechanism, but more class, union,extentInheritance and so on.Unityscriptis byBooLanguage is implemented,BooRun onMonoOn the virtual machine, convert the cost to code execution, andMonois an open-source. NETFramework. In the use ofUnityscriptThe basic types such asChar,string,arrayOnly go straight to the check.MonoThe document.

The above-mentioned users of the famous university test problem actually useCharA method ofIsletterordigitCan be solved easily, but if not to seeMonoDocumentation I'm sure I don't know about that.

SaidUnityscriptAndJavascriptThe difference in fact the officialWikiThere is a more detailed post, I also use these things, a bit into the complex code details, only to find these problems, of course, some things usually also naturally used, such asvar s:int;Such a notation, inJSThe inside isvar s;It is necessary to avoid the overhead of type detection with strongly typed declarations. There are also some areas to be aware of:

1InJSIn the previous variable declarationvarIn some cases it can be omitted, butUnityIf declaring a variable is not usedvar, the scope of this variable is global.
2NoprototypeInheritance mechanism, inherited syntax:class Foo extents Bar {};
3, a virtual function can be defined, and the class can override it, and the syntax isvirtual function do () {something;}, in both the parent and child classes, addVirtualKey words
4, the method of the parent class in the subclass, using theSuperkeywords, such asclass Foo Extents bar{virtual function do () {super. Do (); /*...more code. */ }; }
5, more convenient and concise than inheritance method is to get the parent class component name directly, using its method, use theUnityThe provided functiongetcomponent ()And a little trick, if you use it in a scriptStaticDeclare a variable, use the script name directly in other scripts.Variable can be accessed withoutgetcomponent ()
6、StringUsing subscript operation to getChartypes, such as"Foobar" [3]GetCharType of character' B '
7、UnityscriptEach script is inherited from theMonobehaviourA class that is in theC #AndBooExplicit declaration is required, but theUnityscriptIs implicit and automatic, each script name is a class name, that is, a type name, the variable declared in the global context of the script is actually a property declared as the script class, the global function is actually its method, in this class can also define other classes
8、UnityscriptThere are two types of arrays, the basicArrayAndJavaScriptSimilar toArray, the array of direct quantities such as[1, 2, 3]Belong toArrayType, can only be used subscript operation, can not be usedPushSuch a method, to declare aArrayMust be usedvar a = new Array ()Such a statement, it is recommended to use. NETOfListOverride it, declare the method andC #A little bit different:var myList = new list.<int> ();Note the middle dot symbol
9、UnityscriptUse enumerations in:enum Someenum {AAA, BBB, CCC, DDD};
TenBecauseUnityscriptis run onMonoOn the, you can useMonoLibrary, withimport System; import System.IO (InUnityYou can use this, such as:System.IO.File.Open ()To open a file)
OneBecauseUnityscriptis run onMono, you can use a third-party library, such asxml-rpc.netAnd so on, withImportkeyword to introduce its. DLLFile

OnUnityIn theRotationAndquaternionThe multiplication

Hand-written game after a more personal experience, is the actual operation can test many language details, perhaps usually seeAPIDocument, or to see some tutorials when you do not have a deep understanding, because most of the time you only know how to do, but do not know why to do so, or how to think of doing so, there is no other way? In the project I'm going to use a camera surround script and I find the officialAssetAlready have a script like this, open to see its code is very simple, just more than 10 lines, where the more critical line of code, with the camera'sRotationControl the camera'sposition, this method is very ingenious:

position = Rotation*vector3 (0.0, 0.0,-distance) + target.position;



UnityDefinedquaternionThere are two types of multiplication overloads:

    1. Static operator* (Lhs:quaternion, rhs:quaternion): quaternion
    2. Static operator* (Rotation:quaternion, Point:vector3): Vector3

Copy Code


These two overloads are very different, the first one is to calculate the rotation of an objectLHSRotate it again laterRHS, the whole result is actually equivalent to how much is rotated, and the parameters and return values arequaternion, which is the angle of rotation, and the second is the calculation of a point in the Cartesian coordinate system,RotationAfter the rotation, it will appear in that position and the return value isVector3.
Over hereTargetIs the object that the camera is going to surround,Distanceis to keep the distance, the camera position is calculated to calculate the point. Last night I was wondering why this formula was set up and checkedquaternionOf*Number of overloads to see the fame, before lookingAPII've seen this in the documentation, but I didn't expect it to be magical. We know the angle of rotation of the camera, around an object, can only be left and right and up and down the direction of rotation, along the depth of the rotation is not much meaning (you may feel that the player will also like upside-down angle, but in my project does not need), soRotation.euleranglesMust be(x, y, 0)The form before I was wondering why the point to be turned inZAxis rather than on thexOn the shaft, if it is in thexAxis, then the rotated point isVector3 (-distance, 0, 0), the direction of rotation must go alongyShafts andZAxis, which andRotationOnly inxAndyRotational values on the axis are contradictory.

Another problem that you don't think about or think about seriously is thatRotationHow the angle is calculated. I've always thought thatRotationis the angle of rotation of the relative axis, such as the camera wrapping script,RotationOfxValue is relativexAngle of rotation of the axis, but when the rotating object moves to the world coordinate systemxOn the axis,rotatiionThe value should appear to be0.This inference is obviouslyRotationis calculated relative to its own coordinate system, but it seems to rotate in the local coordinate systemx, yThese three values should all be0Unchanged, because the local coordinate system rotates with the rotation of the object.

Actually, just know.UnityInRotationThe calculation of the amount of rotation, the above problems are solved:

UnityInRotationis of typequaternionUseEuleranglesProperties can be converted intoVector3It is said that we can think of it as a vector, the calculation of the vector is based on the starting point and the vector position of the terminating point, but all vectors have a value computed from the origin of the coordinate system, which is the credential of its position, absolute in the world coordinate system, and the former is relative, the two actually have some kind of unity. Referring to this calculation method, the rotation of the three coordinate values can be explained.UnityCompare the world coordinate system with the local coordinate system, calculate the absolute rotation angle according to the deflection of the local coordinate system relative to the world coordinate system, according to the appliedRotationThe relative rotation angle is calculated by the absolute angle of the coordinate system before rotation and the absolute angle of the subsequent coordinate system. SoRotationWhere is the origin of the point? In the properties panel, put the object'sRotationattribute is attributed to0You can see,RotationThe Origin state is the local and world coordinate systemsx, y, zThree axes in a consistent state.


Download attachments to albums

uploaded 1 minutes ago




For more information, please visit the "Dog Planing Learning Network" http://unity.gopedu.com

Disclaimer: This document is from the "Dog Planing Learning Network" community, is the Netizen self-published Unity3d study articles, if there is any content violated your relevant interests, please communicate with the official, we will deal with the real-time.

Unity Learning Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.