Пример #1
0
    // Use this for initialization
    void Start()
    {
        // init
        m_fly     = 0;
        m_lastHit = Time.time - 1;

        // Calculate world scale
        m_worldScale = HelperFunctions.getWorldScale(gameObject);

        // get controller
        m_controller = GetComponent <CharacterController>();

        // calculate the start velocity to jump
        m_groundFlyValue = 2 * Mathf.Sqrt(GameConfig.ENEMY_JUMP_HEIGHT * m_controller.height * m_worldScale.y * this.transform.localScale.y * Mathf.Abs(Physics.gravity.y));

        // Attach script
        MeshRendererOnVisible.attachScriptToRenderer(gameObject,
                                                     (Camera _camera) =>
        {
            // Player camera?
            if (Camera.current.name.Equals(GameConfig.CAMERA_NAME_PLAYER) == true)
            {
                m_skipUpdate = false;
            }
        });
    }
Пример #2
0
    // Use this for initialization
    internal void Awake()
    {
        m_direction = (this.transform.rotation.eulerAngles.y < 181 && this.transform.rotation.eulerAngles.y > 179) ? 1 : -1;
        m_fly       = 0;

        // Calculate world scale
        m_worldScale = HelperFunctions.getWorldScale(gameObject);

        // get controller
        m_controller     = GetComponent <CharacterController>();
        m_groundFlyValue = (!m_canFly) ? -0.001f : 2 * Mathf.Sqrt(GameConfig.ENEMY_JUMP_HEIGHT * m_controller.height * m_worldScale.y * this.transform.localScale.y * Mathf.Abs(Physics.gravity.y));
        m_lastHit        = Time.time;
        first            = true;

        // calculate death value
        m_deathValue = -Mathf.Sqrt(Mathf.Abs(Physics.gravity.y) * 50 * m_worldScale.y * this.transform.localScale.y);

        // Attach script
        if (m_allowToMove == true)
        {
            MeshRendererOnVisible.attachScriptToRenderer(gameObject,
                                                         (Camera _camera) =>
            {
                // Player camera?
                if (Camera.current.name.Equals(GameConfig.CAMERA_NAME_PLAYER) == true)
                {
                    m_allowToMove = true;
                }
            });
        }
    }
Пример #3
0
    // Override: MonoBehaviour::Start()
    void Start()
    {
        // Get player data
        m_playerData = Game.Instance.PlayerData;

        // Get player
        m_player = GameObject.FindGameObjectWithTag(Tags.TAG_PLAYER);

        // Player dont find?
        if (m_player == null)
        {
            return;
        }

        // Get the character controller from the player
        CharacterController controller = m_player.GetComponent <CharacterController>();

        // Character controller find?
        if (controller == null)
        {
            return;
        }

        // Get the center of the controller
        m_offset = controller.center;

        // Get the scale of the player
        Vector3 playerWorldScale = HelperFunctions.getWorldScale(m_player);

        // Calculate the scale of the player to the offset
        m_offset = new Vector3(m_offset.x * playerWorldScale.x,
                               m_offset.y * playerWorldScale.y,
                               m_offset.z * playerWorldScale.z);

        // Attach script
        MeshRendererOnVisible.attachScriptToRenderer(gameObject,
                                                     (Camera _camera) =>
        {
            // Player camera?
            if (Camera.current.name.Equals(GameConfig.CAMERA_NAME_PLAYER) == true)
            {
                m_skipUpdate = false;
            }
        });
    }
Пример #4
0
    // Tries to attach the script to the mesh renderer with the biggest bounding box
    public static bool attachScriptToRenderer(GameObject _object, Delegate_OnWillRenderObject _callback)
    {
        // Local variables
        MeshRenderer[]        rendererList = null;
        MeshRendererOnVisible script       = null;

        // Validate parameter
        if (_object == null || _callback == null)
        {
            return(false);
        }

        // Get list with all renderer
        rendererList = _object.GetComponentsInChildren <MeshRenderer>();
        foreach (MeshRenderer r in rendererList)
        {
            script = r.gameObject.AddComponent <MeshRendererOnVisible>();
            script.OnWillRender += _callback;
        }

        return(true);
    }