示例#1
0
    void Start()
    {
        player_status= GetComponent<HandlePlayerStatus>();
        collider= GetComponent<Collider2D>();
        if (target == null || pistol == null)
            Debug.Log("Target or Pistol null!!");

        /* To fix... depends on the collider that we have */
        BoxCollider2D box_collider = collider as BoxCollider2D;
        this.box_collider = box_collider;
        var collider_width = box_collider.size.x * Mathf.Abs(transform.localScale.x) - (2 * skin_width);
        _horizontal_distance_between_rays = collider_width / (total_vertical_rays - 1);

        var collider_heigth = box_collider.size.y * Mathf.Abs(transform.localScale.y) - (2 * skin_width);
        _vertical_distance_between_rays = collider_heigth / (total_horizontal_rays - 1);

        animator=GetComponent<Animator>();
        gun=GetComponent<AudioSource>();

        GameObject game_controller = GameObject.Find("GameController") ?? null;
        if (game_controller != null)
        {
            HandlePlayerInput hpi= game_controller.GetComponent<HandlePlayerInput>();
            hpi.player = this.gameObject;
        }
    }
 /* Search the player in the tree (not always will be, such as the main menu */
 void check_player_presence()
 {
     player = GameObject.Find("Player") ?? null;
     if(player!=null)
         player_status = player.GetComponent<HandlePlayerStatus>();
 }