Unity Base Code

Source: Internet
Author: User
Tags array length rewind

1. Find objects by name
Gameobject.find ("Player")
2. Find a subset of objects by name
Transform. Findchild ("Object subset name")
3. Show and Hide objects
Gameobject.setactive (true);?
4. Using and closing object codes
gameobject.getcomponent< code name > (). enable=true;
5. Press the animated event if (Input.getmousebutton (0))
Press the event if (Input.getmousebuttondown (0))
Lift Event if (input.getmousebuttonup (0))
6. Destroying objects of the same label
Gameobject [] Objs = Gameobject.findgameobjectswithtag ("label name");
foreach (Gameobject obj in Objs) {
Destroy (obj);
}
7. Moving objects horizontally at a constant speed
Transform. Translate ( -0.1f*time.deltatime,0,0);
8.<< is divided by 2,>> is multiplied by 2
9. Location-Related: 5 and position-related VECTOR3 type variables
Up represents the y-axis direction of world coordinates
Right represents the X-axis direction of world coordinates
Forward represents the z-axis direction of world coordinates
Position? Represents the position of an object in a world coordinate system
Localposition? Represents the coordinate position of the object relative to the parent node transformation
10. Change the color of the object
Obj.renderer.material.color=color.red
11.2 Variables of type quaternion
Rotation? The rotation angle in the world coordinate system is a quaternion object (four-dollar number)
Localrotation? The rotation angle relative to the parent node
12. Parent-child node Related:
The parent variable represents the parents of the transform node.
Transform Find (string name)? Find child nodes by name
BOOL Ischildof (Transform node)? Determine if the Transform is a child of a Transform
void Detachchildren ()? To disassociate a parent-child relationship from all child nodes
13. Mouse:
Input.mouseposition represents the current pixel position of the mouse (what is the coordinate system?) Take the lower left corner as the origin point)

The next three parameters of the function, 0 left, 1 right, 2 middle
Getmousebutton? Returns True when the corresponding key is in the pressed state
Getmousebuttondown? Returns True when the corresponding key is pressed
Getmousebuttonup? Returns True when the corresponding key bounces
14.
OnMouseDown? callback when mouse clicks to object
Onmousedrag? Called when the mouse is dragged over an object, not on the Ignore Raycast layer
Onmouseenter? Called when the mouse enters the object
Onmouseexit? Called when the mouse leaves the object
OnMouseOver? Called when the mouse hovers over the object
Onmouseupasbutton? The mouse is pressed on the same object, and is called when it bounces
OnMouseUp, just like upstairs.
15.gameobject.transform.rotation
= new Quaternion (player.transform.rotation.x, PLAYER.TRANSFORM.ROTATION.Y, Player.transform.rotation.z, PLAYER.TRANSFORM.ROTATION.W);
Gameobject and player rotate the same angle!
16. Distance between two objects float Distance
float Distance = vector3.destance (Position1,position2);
17. If the distance between the player and the enemy is less than 10, execute the {} code
if (Vector3.destance (enemy position, player. Position) <10f) {
//? Execute the corresponding code
}
18.Animation Animation
01. Rewind Playback Animation.rewind ();
02. Stop all animation animation.stop ();
Stop animation Animation.stop ("animated name");
03. Use the animation cycle mode animation.wropmode= Wropmode.loop;
04. Wait for the animation to finish animation. Play ();???? Yiel Waitforseconds (animation. Clip.length);
05. Print the animated length print (animation["animated name"]. Length);
19. Arrays
foreach (texture2d[] ta in current array) {
The array length is +=ta. Length;//?? The length of the loaded array
}

Unity Base Code

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.