Project 1 Roll a boll notes

The newly created GameObject needs to reset and rename the Transform property, which is a good habit.

Select the GameObject in the view and move the mouse to the scene, click f, it is a shortcut operation to locate the object.

Use script to tell GameObject how to move.

The Transform property of the child object will change with the Transform of the parent object, so if the camera is regarded as a child object, the camera will rotate with the sphere.

The camera moves with the object, which is best done with scripting.

The public properties in the script are displayed in the editor.


//Camera move script

public class cameramove : MonoBehaviour {
    public GameObject player;
    private Vector3 offset;
// Use this for initialization
void Start () {
        offset = transform.position;
}// Update is called once per framevoid LateUpdate () {        transform.position = player.transform.position + offset;}





}

The public GameObject is used to refer to the object that needs to be followed. The variable of private Vector3 is used to record the initial position of the camera,

offset is used in the Start method to record the initial position of the camera.

In the LateUpdate method, add the position of the camera to the position of the object, and the camera follows the object.

The LateUpdate method is executed after the Update method.


The benefits of Prefab prefabs:

1. Make once, reuse

2. With one modification, the properties of the Prefab in all objects that use the Prefab will be changed accordingly.

Tag usage: often used to judge objects in scripts


The script modifies and initializes the score, UItext sets the score panel.


Unity Trigger:

To use Trigger to detect the entry of objects, you need to check the Is Trigger option.
The collision detection trigger Trigger is different from the collision detector Collision, which can not be affected by physical effects. For collision detection of some penetrable areas, you can use Trigger for collision.
Common methods of detection are as follows:
OnTriggerEnter when entering
OnTriggerExit when leaving
OnTriggerStay when on

Ditto for the collision detector Collision also has 3 methods:
OnCollisionEnter
OnCollisionExit
OnCollisionStay

The parameter passed in OnTriggerEnter must be Collider, so the object that can trigger this function must have the Collider component


Basic rules: The script (with the OnTriggerEnter() judgment function that triggers judgment) and the Rigibody are the same component of the object, and the Box Collider must be selected. At this time, the Box Collider of the two objects must be selected. The Is Trigger option must have "at least" one object selected (which can be logically determined as a trigger). OnTriggerEnter() in the script can have two ways to judge and start. The data type of this function parameter is Collider. function OnTriggerEnter( gameObj : Collider ), once the trigger and Collider collide, this function will be triggered, and its parameter is the gameObject of the object that does not contain the script. You can determine which object is by judging the string of its member name (the object's name in the Hierarchy panel) or tag (the object's name in the Tag option of the Inspector panel).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324607594&siteId=291194637