Ejemplo n.º 1
0
    //_objは必ずプレイヤーのHitBox
    public static ObjectCaller GetObjectCaller(GameObject _obj)
    {
        //HitBox hitbox = _obj.GetComponent<HitBox>();
        //ヒットした側のゲームオブジェクトは保存できないのか
        Collider2D   hit_col    = _obj.GetComponent <Collider2D>();
        GameObject   hitbox     = hit_col.gameObject;
        HitBox       hitbox_ins = hitbox.GetComponent <HitBox>();
        ObjectCaller caller     = hitbox_ins.chara_caller;

        return(caller);
    }
Ejemplo n.º 2
0
    protected void ParentStart()
    {
        audioPlayer       = GameObject.Find("AudioList").GetComponent <AudioPlayer>();
        gameobject_player = GameObject.Find("TestPlayer");

        rigidbody2d = GetComponent <Rigidbody2D>();
        clash       = new C_Clash();
        clash.Init(GetComponent <BoxCollider2D>());//これだと現状キャラクターの当たり判定はBoxColliderしか使えない
        caller      = GetComponent <ObjectCaller>();
        renderer    = GetComponent <SpriteRenderer>();
        First_Color = renderer.color;
    }
Ejemplo n.º 3
0
    public bool Action(Transform _transform, ObjectCaller _caller)
    {
        if (time > 0.05f)
        {
            Trigger = false;
        }
        if (!Active)
        {
            return(false);
        }
        Vector2 vectorfor2d;

        vectorfor2d.x = _transform.position.x;
        vectorfor2d.y = _transform.position.y;
        float   HitBox_x            = col.size.x * 0.5f * _transform.localScale.x;                      //HitBoxのヨコの実長
        float   HitBox_y            = col.size.y * 0.5f * _transform.localScale.y;                      //HitBoxのヨコの実長
        Vector2 ColliderRayVector_x = vector.normalized * (HitBox_x / Mathf.Abs(vector.normalized.x));  //HitBOx_xを基に長さを調節したRayVector
        Vector2 ColliderRayVector_y = vector.normalized * (HitBox_y / Mathf.Abs(vector.normalized.y));; //HitBOx_yを基に長さを調節したRayVector
        Vector2 RayVector;

        if (ColliderRayVector_x.magnitude < ColliderRayVector_y.magnitude)
        {
            RayVector = ColliderRayVector_x;
        }
        else
        {
            RayVector = ColliderRayVector_y;
        }                                                                                                                                               //↑二つのうち長さが短い方を採用
        ray2d = new Ray2D(vectorfor2d, RayVector);
        Debug.DrawRay(ray2d.origin, ray2d.direction.normalized * RayVector.magnitude, Color.green, 1, false);
        if (true)
        {
            //コーラーの壁ヒットフラグがONならTranslateのみ更新を停止
            //if (!_caller.WallHit)
            RaycastHit2D hit = Physics2D.Raycast(ray2d.origin, ray2d.direction.normalized, 1.0f * RayVector.magnitude);
            if (hit.collider == null || hit.collider.tag != "Wall")
            {
                _transform.Translate(scaler * vector * Time.deltaTime * speed);
            }
            else
            {
                //
            }
        }
        tmp_scaler += scaler * Time.deltaTime * speed;
        if (tmp_scaler >= scaler)
        {
            Active          = false;
            _caller.WallHit = false;
        }
        time += Time.deltaTime;
        return(true);
    }
Ejemplo n.º 4
0
    [HideInInspector] public ObjectCaller chara_caller;//攻撃を当てたEnemyのコーラー
    void OnTriggerEnter2D(Collider2D Chara_col)
    {
        //Enemyのコーラーを取得
        GameObject objop = Chara_col.gameObject;

        if (objop.tag == "Enemy" || objop.tag == "Player")
        {
            chara_caller = objop.GetComponent <ObjectCaller>();
            if (chara_caller.AttackHit)
            {
                //IsHit = true;
            }
        }
        if (status.DeleteToHit)
        {
            //タグを変えることによる強制回避
            //GameObject.tag = "UnTagged";
            Destroy(gameObject);
        }
    }
Ejemplo n.º 5
0
    void OnTriggerEnter2D(Collider2D col)
    {
        //敵か味方の場合
        if (col.tag == "Enemy" || col.tag == "Player")
        {
            //壁の少し外側で当たったことをオブジェクトに通知する
            GameObject   objcol    = col.gameObject;
            ObjectCaller caller    = objcol.GetComponent <ObjectCaller>();
            Charactor    chara_ins = objcol.GetComponent <Charactor>();
            if (chara_ins != null)
            {
                C_Clash clash = chara_ins.clash;
            }
            if (caller != null)
            {
                caller.WallHit = true;
            }

            //if(clash.Active)
        }
        else
        {
        }
    }