Answers for "unity functions list"

C#
1

unity functions list

// Event Functions

//a script in Unity is not like the traditional idea of a program where the code runs continuously in a loop until it completes its task. Instead, Unity passes control to a script
//intermittently by calling certain functions that are declared within it. Once a function has finished executing, control is passed back to Unity. These functions are known
//as event functions since they are activated by Unity in response to events that occur during gameplay. Unity uses a naming scheme to identify which function to call for a
//particular event. For example, you will already have seen the Update function (called before a frame update occurs) and the Start function (called just before the object’s
//first frame update). Many more event functions are available in Unity; the full list can be found in the script reference page for the MonoBehaviour class along with
//details of their usage. The following are some of the most common and important events.

//Regular Update Events

void Update() {
    float distance = speed * Time.deltaTime * Input.GetAxis("Horizontal");
    transform.Translate(Vector3.right * distance);
}

void FixedUpdate() {
    Vector3 force = transform.forward * driveForce * Input.GetAxis("Vertical");
    rigidbody.AddForce(force);
}

void LateUpdate() {
    Camera.main.transform.LookAt(target.transform);
}


//GUI events

void OnGUI() {
    GUI.Label(labelRect, "Game Over");
}

//Physics events

void OnCollisionEnter(otherObj: Collision) {
    if (otherObj.tag == "Arrow") {
        ApplyDamage(10);
    }
}
Posted by: Guest on July-29-2021

C# Answers by Framework

Browse Popular Code Answers by Language