Example #1
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Attack")
        {
            HitScript hit = other.gameObject.GetComponent <HitScript>();

            if (hit != null && hit.target.gameObject == this.gameObject)
            {
                object[] hitPoses = new object[] {
                    other.gameObject.transform.position.x,
                    other.gameObject.transform.position.y,
                    other.gameObject.transform.position.z
                };

                //当たったエフェクトの生成
                photonView.RPC(nameof(CreateHitEffect), RpcTarget.All, hitPoses);
                //処理
                photonView.RPC(nameof(DownHP), RpcTarget.All, hit.Damage);
                PhotonNetwork.Destroy(other.gameObject);
                Rival.transform.Translate(-Vector3.forward);
                //GetComponent<Rigidbody>().velocity = -transform.forward * 1;
                Debug.Log(this + "damage");
            }
        }
    }
Example #2
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if ((other.tag == "Grenade" || other.tag == "Bullet") && !Invincible)
     {
         HitScript HS = other.GetComponent <HitScript>();
         if (other.tag == "Grenade" || ((!Invincible) && (!(HS.GetOwner() == PCS.GetPlayerNum()))) && !HS.DamageInactive)
         {
             if (HS.IsKnife)
             {
                 HS.DamageInactive = true;
             }
             SPS.playHit();
             if (HS.GetBulletNumber() > bulletNumbers[HS.GetOwner()])
             {
                 bulletNumbers[HS.GetOwner()] = HS.GetBulletNumber();
                 Stats.IncrementHits(HS.GetOwner());
             }
             Stats.IncrementDamageDone(HS.GetOwner(), HS.GetDamage());
             health = health - HS.GetDamage();
             StopAllCoroutines();
             StartCoroutine(lerpHit());
             HealthCheck(HS.GetOwner());
             HS.Kill(transform.position, true);
         }
         else if (!(HS.GetOwner() == PCS.GetPlayerNum()))
         {
             HS.Kill(transform.position, false);
         }
     }
 }
Example #3
0
    public void killed()
    {
        HitScript particle = Instantiate <HitScript> (hitScript);

        particle.transform.position = transform.position;
        Destroy(this.gameObject);
    }
Example #4
0
    public static void MakeAttacker(GameObject target, GameObject me, CardManager.CardData cardData, PhotonView pv)
    {
        // ヒットボックス作成
        GameObject attacker;

        // 小物があれば
        if (cardData.accessory != null)
        {
            // 基礎オブジェクトを作成
            attacker = PhotonNetwork.Instantiate(cardData.accessory.ToString(), Vector3.zero, Quaternion.identity);
        }
        else
        {
            // 空のオブジェクト作成
            attacker = PhotonNetwork.Instantiate("attackOBJ", Vector3.zero, Quaternion.identity);
        }
        // ボックス判定導入
        attacker.AddComponent <BoxCollider>();

        // 一旦ボックスを保持する
        BoxCollider box = attacker.GetComponent <BoxCollider>();

        // ステータスセット
        box.transform.position = me.transform.position + (me.transform.rotation * cardData.GenerationPoint);
        box.size = cardData.Size;
        // 判定をトリガー(衝突なし)に変更
        box.isTrigger = true;

        // 攻撃データ導入
        attacker.AddComponent <HitScript>();
        // 一旦攻撃データを保持する
        HitScript hitData = attacker.GetComponent <HitScript>();

        // ターゲット指定
        hitData.target = target;
        // ダメージ値をセット
        hitData.Damage = cardData.Damage;
        // 生存時間
        hitData.life = cardData.Life;
        // 攻撃オブジェクトとしてタグ付け
        attacker.tag = "Attack";

        // 回転
        Vector3    vecTarget = target.transform.position - me.transform.position;
        Quaternion rotTarget = Quaternion.LookRotation(vecTarget);

        attacker.transform.rotation = rotTarget;

        // 移動したなら
        if (cardData.Velocity.magnitude > 0)
        {
            // 重力を消す
            attacker.GetComponent <Rigidbody>().useGravity = false;
            // 移動量をセット
            hitData.Velocity = rotTarget * cardData.Velocity;
        }
    }
Example #5
0
    private void OnTriggerStay(Collider other)
    {
        PushObjectScript pushobject = other.GetComponent <PushObjectScript>();

        if (pushobject && Input.GetButtonDown("Push") && !_isKicking)
        {
            _pushObject = pushobject;
            KickObject(other.transform);
            return;
        }

        WeaponScript weapon = other.GetComponent <WeaponScript>();

        if (weapon && Input.GetButtonDown("Interact") && !_isPickingUp)
        {
            _weaponScript = weapon;
            _isPickingUp  = true;
            _animationController.pickUpWeaponIK.WeaponScript = weapon;
            _animationController.Pickup();
            weapon.DisablePickUp();
            _playerMovement.Stop();
        }

        HitScript tohit = other.GetComponent <HitScript>();

        if (tohit && _pickedUp && Input.GetButtonDown("Interact") && !_isHitting)
        {
            _enemyController = other.GetComponent <EnemyController>();
            _toHit           = tohit;
            _isHitting       = true;
            Hit(other.transform);
            _toHit.DisableHitbox();
            _playerMovement.Stop();
        }


        if (other.tag == "Seen" && !_isHitting)
        {
            _enemyController = other.GetComponentInParent <EnemyController>();
            _isSeen          = true;
            _playerMovement.Stop();
            Seen(other.transform.parent);
        }

        if (other.gameObject.tag == "Fall")
        {
            Fall();
        }

        if (other.gameObject.tag == "Win")
        {
            _playerMovement.Stop();
            WinGame();
        }
    }
Example #6
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Bullet" || other.tag == "Boomerang")
     {
         HitScript HS = other.GetComponent <HitScript> ();
         if ((HS.GetOwner() == PCS.GetPlayerNum()) && HS.IsBoomerang)
         {
             AS.ReloadSingle();
             HS.KillBoomerang();
         }
     }
 }
Example #7
0
    public void CreateHitEffect(float posX, float posY, float posZ)
    {
        GameObject eff = GameObject.Instantiate(HitEffect);

        eff.transform.position = new Vector3(posX, posY, posZ);
        eff.AddComponent <HitScript>();

        //HitScriptの魔改造
        HitScript scr = eff.GetComponent <HitScript>();

        scr.life      = 1.0f;
        scr.isNetwork = false;
    }
Example #8
0
    void OnTriggerEnter2D(Collider2D otherCollider)
    {
        HitScript shot = otherCollider.gameObject.GetComponent <HitScript>();

        if (shot != null)
        {
            if (shot.isEnemyShot != isEnemy)
            {
                Damage(shot.damage);

                Destroy(shot.gameObject);
            }
        }
    }
Example #9
0
    public void Attack(bool isEnemy)
    {
        if (CanAttack)
        {
            shootCooldown = shootRate;

            var shotTransform = Instantiate(shotPrefab) as Transform;

            shotTransform.position = transform.position;

            HitScript shot = shotTransform.gameObject.GetComponent <HitScript>();
            if (shot != null)
            {
                shot.isEnemyShot = isEnemy;
            }

            MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>();
            if (move != null)
            {
                move.direction = this.transform.right;
            }
        }
    }
Example #10
0
 public override void InitiateSpell()
 {
     isChannelling = true;
     hitScript     = meteor.GetComponent <HitScript>();
 }
Example #11
0
    public void ShootLine(int count, Color c, Vector3 playerTrans, Vector3 playerUp, int pNum, int bulletNumber)
    {
        for (int x = 0; x < 3; x++)
        {
            hitbox[x].gameObject.SetActive(false);
        }
        int          Layer = 1 << 9;
        RaycastHit2D hit, hit2, hit3;

        hit = Physics2D.Raycast(playerTrans, playerUp, Mathf.Infinity, Layer);

        LR.SetVertexCount(count * 2);
        LR.SetPosition(0, playerTrans);
        LR.SetPosition(1, hit.point);
        particles.transform.position = hit.point;

        //calculate angle
        Vector2 diff  = (Vector2)playerTrans - hit.point;
        float   angle = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;

        // set angle distance and turn on hitbox
        hitbox [0].transform.position = Vector3.MoveTowards(playerTrans, hit.point, hit.distance / 2);
        hitbox [0].size = new Vector2(hit.distance, .3f);
        hitbox [0].transform.eulerAngles = new Vector3(0, 0, angle);
        // set the hitbox info for section 3
        HitScript HS = hitbox [0].GetComponent <HitScript> ();

        HS.BulletDamage = count;
        HS.SetBulletNumber(bulletNumber);
        HS.SetOwner(pNum);

        hitbox[0].gameObject.SetActive(true);

        // do next section if lazer is longer
        if (count > 1)
        {
            Vector2 diffMiddle = new Vector2(hit.point.x - playerTrans.x, hit.point.y - playerTrans.y);
            hit2 = Physics2D.Raycast(hit.point, Vector3.Reflect(diffMiddle.normalized, hit.normal), Mathf.Infinity, Layer);

            diff  = (Vector2)hit.point - hit2.point;
            angle = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
            // set angle distance and turn on hitbox
            hitbox [1].transform.position = Vector3.MoveTowards(hit.point, hit2.point, hit2.distance / 2);
            hitbox [1].size = new Vector2(hit2.distance, .3f);
            hitbox [1].transform.eulerAngles = new Vector3(0, 0, angle);
            // set the hitbox info for section 3
            HS = hitbox [1].GetComponent <HitScript> ();
            HS.BulletDamage = count;
            HS.SetBulletNumber(bulletNumber);
            HS.SetOwner(pNum);

            // linerender points
            LR.SetPosition(1, Vector3.MoveTowards(hit.point, playerTrans, .01f));
            LR.SetPosition(2, hit.point);
            LR.SetPosition(3, hit2.point);
            hitbox[1].gameObject.SetActive(true);
            // if final charge
            if (count > 2)
            {
                diffMiddle = new Vector2(hit2.point.x - hit.point.x, hit2.point.y - hit.point.y);
                hit3       = Physics2D.Raycast(hit2.point, Vector3.Reflect(diffMiddle.normalized, hit2.normal), Mathf.Infinity, Layer);

                diff  = (Vector2)hit2.point - hit3.point;
                angle = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
                // set angle distance and turn on hitbox
                hitbox [2].transform.position = Vector3.MoveTowards(hit2.point, hit3.point, hit3.distance / 2);
                hitbox [2].size = new Vector2(hit3.distance, .3f);
                hitbox [2].transform.eulerAngles = new Vector3(0, 0, angle);
                // set the hitbox info for section 3
                HS = hitbox [2].GetComponent <HitScript> ();
                HS.BulletDamage = count;
                HS.SetBulletNumber(bulletNumber);
                HS.SetOwner(pNum);

                // linerenderer points
                LR.SetPosition(3, Vector3.MoveTowards(hit2.point, hit.point, .01f));
                LR.SetPosition(4, hit2.point);
                LR.SetPosition(5, hit3.point);
                hitbox[2].gameObject.SetActive(true);
            }
        }

        gameObject.SetActive(true);
        StartCoroutine(colorAnim(c));
        Invoke("TurnOff", .2f);


        /* old code that does not hangle corners well
         * int Layer = 1 << 9;
         * RaycastHit2D hit = Physics2D.Raycast (playerTrans, playerUp, Mathf.Infinity, Layer);
         * RaycastHit2D hitLeft = Physics2D.Raycast (playerTrans - (playerRight * .2f), playerUp, Mathf.Infinity, Layer);
         * RaycastHit2D hitRight = Physics2D.Raycast (playerTrans + (playerRight * .2f), playerUp, Mathf.Infinity, Layer);
         * RaycastHit2D hit2, hit2Left, hit2Right, hit3, hit3Left, hit3Right;
         *
         *
         * LR.SetVertexCount (count * 2);
         * LR.SetPosition (0, playerTrans);
         * LR.SetPosition (1, hit.point);
         *
         * Vector2[] edges = new Vector2[2+(2*count)];
         * edges [0] = playerTrans - (playerRight * .2f);
         * edges [1] = hitLeft.point;
         * edges [2] = hitRight.point;
         * edges [3] = playerTrans + (playerRight * .2f);
         * particles.transform.position = hit.point;
         * if (count > 1) {
         *      Vector2 diffMiddle = new Vector2( hit.point.x - playerTrans.x, hit.point.y - playerTrans.y);
         *      hit2Left = Physics2D.Raycast (hitLeft.point, Vector3.Reflect(diffMiddle.normalized, hit.normal), Mathf.Infinity, Layer);
         *      hit2 = Physics2D.Raycast (hit.point, Vector3.Reflect(diffMiddle.normalized, hit.normal), Mathf.Infinity, Layer);
         *      hit2Right = Physics2D.Raycast (hitRight.point, Vector3.Reflect(diffMiddle.normalized, hit.normal), Mathf.Infinity, Layer);
         *
         *      LR.SetPosition(1,Vector3.MoveTowards(hit.point, playerTrans, .01f));
         *      LR.SetPosition (2, hit.point);
         *      LR.SetPosition (3, hit2.point);
         *
         *      edges [2] = hit2Left.point;
         *      edges [3] = hit2Right.point;
         *      edges [4] = hitRight.point;
         *      edges [5] = playerTrans + (playerRight * .2f);
         *
         *      particles.transform.position = hit2.point;
         *      if (count > 2){
         *              diffMiddle = new Vector2( hit2.point.x - hit.point.x, hit2.point.y - hit.point.y);
         *              hit3Left = Physics2D.Raycast (hit2Left.point, Vector3.Reflect(diffMiddle.normalized, hit2.normal), Mathf.Infinity, Layer);
         *              hit3 = Physics2D.Raycast (hit2.point, Vector3.Reflect(diffMiddle.normalized, hit2.normal), Mathf.Infinity, Layer);
         *              hit3Right = Physics2D.Raycast (hit2Right.point, Vector3.Reflect(diffMiddle.normalized, hit2.normal), Mathf.Infinity, Layer);
         *
         *              LR.SetPosition(3,Vector3.MoveTowards(hit2.point, hit.point, .01f));
         *              LR.SetPosition (4, hit2.point);
         *              LR.SetPosition (5, hit3.point);
         *
         *
         *              edges [3] = hit3Left.point;
         *              edges [4] = hit3Right.point;
         *              edges [5] = hit2Right.point;
         *              edges [6] = hitRight.point;
         *              edges [7] = playerTrans + (playerRight * .2f);
         *
         *              particles.transform.position = hit3.point;
         *      }
         * }
         *
         * EC.points = edges;
         * gameObject.SetActive (true);
         * StartCoroutine (colorAnim (c));
         * Invoke ("TurnOff", .2f);*/
    }