Unity3d Study Notes (iii)

Source: Internet
Author: User

Work Site View:


Airplane mode: Press and hold the right mouse button W s a D around the current view, Q E to navigate up and down. Invalid need perspective view in cross mode


Move adsorption: Moving State (W) ctrl+shif move adsorption on other objects


Vertex adsorption: Moving State (W) v-key moves the adsorption on other objects


Specific incremental move: Move state (W) CTRL, move in a specific increment, and be able to set incremental edit-snapsettings.


Use of Unity Scripts

void Start () {SCRIPTB SB = getcomponent<scriptb> (); sb. Say ();} void Update () {this.transform.Rotate (new Vector3 (0,speed * time.deltatime,0)); Rigidbody.mass = Mathf.sin ( Time.deltatime) +1;}

! The properties on the Gameobject can be used directly. There's no way to get access through getcomponent.
. Usually transform can also replace gameobject for use eg:transform.renderer ... Suppose a Gameobject object cannot be displayed in a scene without a transform component and can only be used to store data (why it is not understood to replace gameobject use).
Public Transform Target;


void Update () {  target.renderer.material.color = color.red;} Public gameobject target;void Start () {target = Gameobject.find ("Main camera/sphere");}


//The above assumes that there are multiple names for sphere he's looking for the front one .
//Tag access
T
Arget = Gameobject.findwithtag ("Fuck"); Gameobject.findgameobjectwithtag ("Fuck" gameobject.findgameobjectswithtag ("fuck");   Multiple


Time class:
void Ongui () {Guilayout.label ("Current time:" + time.time); Guilayout.label ("From the previous frame time:" + time.deltatime); Guilayout.label ("Fixed incremental time:" + time.fixedtime); Guilayout.label ("Fixed incremental interval:" + time.fixeddeltatime); Guilayout.label ("Smoothed delata Time:" + time.smoothdeltatime);//increment time can be set in Edit-projectsetting-time}





Keywordyield:used in an iterator block to provide a value to an enumerator object or to emit an iterative end signal.           The iterator block has two special statements: yield return <expression_r_r_r_r>;   Yield break; Iterator Block
An iterator block is a block of code that has one or more yield statements. One of the following three types of code blocks can be an iterator block: Method principal access principal operator body
The yield statement can only be present in the iterator block, which is used as the body of a method, operator, or a listener.

The body of such a method, operator, or listener is controlled by the following constraints:
Do not agree with unsafe blocks.


The parameters of the method, operator, or inspector cannot be ref or out.



void Start () {startcoroutine ("Example");//trigger Print with Startcoroutine ("Hello");p rint ("World");}       A function that uses yield all must set the return value type to IEnumerator type IEnumerator Example () {print (time.time); yield return new waitforseconds (2); Print (time.time);}

similar to settimeout in as and JS


Random:
void Start () {print (random.seed);p rint (random.value);p rint (Random.range (0,1));p rint (Random.range (0.0f,1.0f));}




Returns a random integer number betweenmin [inclusive] and Max [exclusive] (Read only).
If Max Equalsmin, Min'll be returned. The returned value would never bemax unless min equals max.




Inter-object communication
(1) communication between objects with hierarchical relationships
BroadcastmessageCalls The method named MethodName on every monobehaviour in this game object or any of its children.
SendMessageCalls The method named MethodName on every monobehaviour in this game object.
SendmessageupwardsCalls The method named MethodName on every monobehaviour in this game object and on every ancestor of the behaviour.

public class Sendmessageupward:monobehaviour {void OnMouseOver () {sendmessageupwards ("Someonesay", "Fuck U");}} public class Recievemessage:monobehaviour {void Someonesay (string str) {print ("someonesaied" +str);}}




(2) communication without a hierarchical relationship. The ability to commit events through C #
public class Eventdispatcher:monobehaviour {public delegate void EventHandler ();p ublic event EventHandler Mouseover;voi D OnMouseOver () {if (MouseOver! = null) {MouseOver ();}}} public class Eventlistener:monobehaviour {public Gameobject dispatcher;//with this for initializationvoid Start () {Even Tdispatcher ds = Dispatcher. Getcomponent<eventdispatcher> ();d S. MouseOver +=listen;} void Listen () {transform. Rotate (New Vector3 (0,10*time.deltatime,0)); transform.renderer.material.color = Color.cyan;}}


Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Unity3d Study Notes (iii)

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.