コード例 #1
0
ファイル: WeponSystem.cs プロジェクト: Mrpye/unity_space_game
    /// <summary>
    /// This fires the beam lazer
    /// this is the mining beam
    /// </summary>
    private void Fire_Beam()
    {
        if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        if (Input.GetButton("Fire2") && Is_Malfunctioning() && this.is_online && this.active && !UnityFunctions.controls_locked)
        {
            int hit_mask = (1 << LayerMask.NameToLayer("game-assets")) | (1 << LayerMask.NameToLayer("Enemy"));
            StartUsage();
            RaycastHit2D hit2D = Physics2D.Raycast(transform.position, transform.up, laser_range, hit_mask);
            if (hit2D)
            {
                laser_hit_sprite.transform.position = hit2D.point;
                laser_hit_sprite_renderer.enabled   = true;
                //test if has a meterial spawner
                ItemSpawner ms = hit2D.collider.gameObject.GetComponent <ItemSpawner>();
                if (ms != null)
                {
                    ms.Hit(laser_hit_sprite.transform.position);
                }
            }
            else
            {
                laser_hit_sprite.transform.position = transform.position + transform.up * laser_range;
                laser_hit_sprite_renderer.enabled   = false;
            }

            line_renderer.SetPosition(0, transform.position);
            line_renderer.SetPosition(1, laser_hit_sprite.transform.position);
            line_renderer.enabled      = true;
            line_renderer.sortingOrder = this.order_layer - 1;
        }
        else
        {
            line_renderer.enabled = false;
            if (laser_hit_sprite_renderer != null)
            {
                laser_hit_sprite_renderer.enabled = false;
            }
            StopUsage();
        }
    }