Untitled

 avatar
unknown
plain_text
4 years ago
2.0 kB
4
Indexable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private float interval = 1;
    private int intervalCounter = 0;
    private float dt = 0;
    private void Awake()
    {
        Debug.Log("Awake()");
    }

    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Start()");
    }

    // Update is called once per frame
    void Update()
    {
        // dt += Time.deltaTime;
        // intervalCounter++;
        // if(dt >= interval)
        // {
        //     Debug.Log("Update() frames: "+ intervalCounter + " / " + interval + "s");
        //     intervalCounter = 0;
        //     dt = 0;
        // }
        
    }
    // FixedUpdate is called in fixed time interval (default 0,02s --> 50/s)
    // Preferable to use when gameobjects contains physics
    private void FixedUpdate()
    {
        dt += Time.fixedDeltaTime; // returns fixed time delta between frames
        intervalCounter++;
        if(dt >= interval)
        {
            Debug.Log("FixedUpdate() physics updates: "+ intervalCounter + " / " + interval + "s");
            intervalCounter = 0;
            dt = 0;
        }
    }
    private void OnCollisionEnter(Collision collision) // when two gameobjects - having collision with "isTrigger" collides
    {
        if(collision.gameObject.tag.Equals("Ground"))
            Debug.Log("OnCollisionEnter() to Ground");
        else
            Debug.Log("OnCollisionEnter() to other object having tag: " +collision.gameObject.tag);

    }
    private void OnCollisionStay(Collision collision)
    {
        Debug.Log("OnCollisionStay() to object having tag: " +collision.gameObject.tag);
    }
    private void OnCollisionExit(Collision collision)
    {
        Debug.Log("OnCollisionExit() to object having tag: " +collision.gameObject.tag);
    }
}
Editor is loading...