My Unity3d study diary -03 (Input,gameobject,vector3)

Source: Internet
Author: User

Although the previous tutorials were brief but too fragmented, the lessons were not organized. So we re-found a set of tutorials, skip the previous part of the basic knowledge of unity, the script part from the beginning to look at, the following is a little note.


Common methods in the input class

BOOL W=input.getkey (KEYCODE.W);//detect whether to press the keyboard W

Input.getkeydown (KEYCODE.W);//Indicates when the detection is pressed

Input.getkeyup (KEYCODE.W);//Indicates when the detection button bounces

Input.getmousebutton (0);//Parameter 0 for left key, 1 for right, 2 for middle key

The methods of Getmouseup and Getmousedown are similar to the principles of the keyboard

Some common methods on the gameobject itself

Gameobject.name= "Old Wang";

Gameobject.tag = "Player";

BOOL active = gameobject.activeself;//Gets the activation state of the game object

Gameobject.setactive (FALSE); Do not enable the current game object

Gameobj0 obj0 = gameobject.getcomponent<gameobj0> ();//Gets an additional component of the object itself

Print (obj0.age);

Light l=gameobject.addcomponent<light> (); Add a component to the current object

How to find another game object in one game object

Gameobject A;

A = Gameobject.findgameobjectwithtag ("Cube");

Print (a.name);//use tag to find the game object

Gameobject B = Gameobject.find ("Main Camera");

B.name = "Master camera";//Find Game objects by object name

Gameobject.destroy (A,2F); Destroy a Game object, 2f indicates the delay of destruction (2 seconds)

About Vector3

Vector3 v=new Vector3 ();//vector3 is a class used to represent a three-dimensional vector

float x= v.x;

float y= v.y;

Float z= v.z;//xyz in three directions respectively

v=vector3.up;//represents the unit vector of the positive y-axis in the world coordinate system

v = vector3.down;//represents the unit vector for the negative direction of the Y axis in the World coordinate system

v = vector3.right;//represents the unit vector of the positive x-axis in the world coordinate system

v = vector3.left;//represents the unit vector of the x-axis negative direction in the world coordinate system

Forward is the z-axis positive direction, back is the z-axis negative direction, zero indicates the origin.

V.normalize ();//the unit vector that changes V to V

v=v.normalized;//returns a unit vector in v direction, v itself unchanged

float L = v.magnitude;//Gets the length of V

float a = vector3.angle (v1, v2);//Find the angle of two vectors, the return value is not positive or negative

Float d=vector3.distance (V1,V2);//Find the distance between the end of two vectors

Vector3.dot (v1, v2);//dot multiply by two vectors

Vector3.cross (V1,V2);//fork by two vectors

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.