Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (!pc.onGround)
        {
            // 下方向にレイを飛ばして判定
            fromPos = new Vector3(leg.transform.position.x, leg.transform.position.y, leg.transform.position.z + 0.01f);
            Debug.DrawRay(fromPos, direction.normalized * length, Color.green, 1, false);

            if (Physics.Raycast(fromPos, direction, out hit, length))
            {
                if (hit.collider.tag == "Enemy")
                {
                    var ec = hit.collider.GetComponent("enemyController") as enemyController;
                    ec.SetState(enemyController.ENEMY_STATE.DEAD);
                    // SEの再生
                    se.SEPlay(SEController.SE_LABEL.SE_TREAD);
                    pc.Velocity.y += pc.jumpPawer / 2;
                }
            }
            if (Physics.Raycast(fromPos, direction, out hit, length))
            {
                if (hit.collider.tag == "ItemShoot")
                {
                    var Item = hit.collider.GetComponent("ItemShoot") as ItemShoot;
                    Item.SetState(ItemShoot.ITEM_SHOOT_STATE.STAY);
                    // SEの再生
                    se.SEPlay(SEController.SE_LABEL.SE_TREAD);
                }
            }
        }
    }
Exemple #2
0
    // 生成
    public void GenerateItem(ITEM_TYPE Item, Vector3 position)
    {
        position.y += 1;
        var root = GameObject.Find("ItemRoot");

        switch (Item)
        {
        // アイテムの種類判断
        case ITEM_TYPE.ITEM_PAWERUP:
            SE.SEPlay(SEController.SE_LABEL.SE_PAWERUPITEM_GENERATE);
            var Player = GameObject.FindGameObjectWithTag("Player");
            var pc     = Player.GetComponent("PlayerController") as PlayerController;
            if (pc.State == PlayerController.PLAYER_STATE.PLAYER_NORMAL)
            {
                ItemObject = ItemMushroomPrefab;
            }
            else
            {
                ItemObject = ItemFlowerPrefab;
            }
            break;

        case ITEM_TYPE.ITEM_STAR:
            ItemObject = ItemStarPrefab;
            break;

        case ITEM_TYPE.ITEM_COIN:
            ItemObject = ItemCoinPrefab;
            break;
        }
        var item = Instantiate(ItemObject, position, ItemObject.transform.rotation) as GameObject;

        item.transform.parent = root.transform;
    }
Exemple #3
0
    void HitItemBlock()
    {
        BlockLife--;
        if (ItemType == ItemController.ITEM_TYPE.ITEM_COIN)
        {
            GameObject GameRule = GameObject.Find("GameRule");
            GameRule   Rule     = GameRule.GetComponent("GameRule") as GameRule;
            Rule.GetCoin();
            se.SEPlay(SEController.SE_LABEL.SE_COIN);
        }
        var Root     = GameObject.Find("ItemRoot");
        var ItemCtrl = Root.GetComponent("ItemController") as ItemController;

        ItemCtrl.GenerateItem(ItemType, transform.position);
        if (BlockLife == 0)
        {
            gameObject.renderer.material.color       = new Color(1, 1, 1, 0);
            gameObject.renderer.material.mainTexture = null;
            BlockType = BLOCK_TYPE.NONE_BLOCK;
        }
    }
    // プレイヤー操作
    void PlayerControll()
    {
        // プレイヤーが操作可能な場合のアップデート
        if (PlayerControllFlag)
        {
            // LSHIFTでダッシュフラグを立てる
            if (Input.GetKey(KeyCode.LeftShift))
            {
                Dash = true;
            }
            else
            {
                Dash = false;
            }

            if (State == PLAYER_STATE.PLAYER_FIRE)
            {
                // ファイアーボール
                if (Input.GetKeyDown(KeyCode.Q))
                {
                    var Fb       = Instantiate(FireBallPrefab, new Vector3(transform.position.x, transform.position.y + 1, transform.position.z), transform.rotation) as GameObject;
                    var FireBall = Fb.GetComponent("Fireball") as Fireball;
                    FireBall.GenerateFireBall(new Vector3(0f, 0f, 1f));
                    // SEの再生
                    SE.SEPlay(SEController.SE_LABEL.SE_FIREBALL);
                }
            }
            if (Dash)
            {
                Speed = DashSpeed;
            }
            else
            {
                Speed = DefaultSpeed;
            }
            if (!Damage)
            {
                // 左右入力で移動
                Velocity.x = Input.GetAxis("Horizontal") * Speed;
            }



            if (Velocity.x > 0)
            {
                oldVector = 1;
            }
            else if (Velocity.x < 0)
            {
                oldVector = -1;
            }

            transform.rotation = Quaternion.LookRotation(new Vector3(oldVector, 0f, 0f));

            // ジャンプ処理
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (Col.isGrounded)
                {
                    // ジャンプSEの再生
                    PlayerSE.PlayerSEPlay(PlayerSEManager.PLAYER_SE_LABEL.PLAYER_SE_JUMP);
                    Jump = true;
                    SendMessage("OnJump", SendMessageOptions.DontRequireReceiver);
                }
            }
            // 長押し対応
            if (Input.GetKey(KeyCode.Space) && Jump)
            {
                if (jumpCounter < 25f && Jump)
                {
                    jumpCounter++;
                    Velocity.y = jumpPawer;
                }
            }
            else
            {
                Jump = false;
            }

            if (Input.GetKeyUp(KeyCode.Space))
            {
                jumpCounter = 100;
            }

            if (Jump || !Ground)
            {
                if (!blockHit)
                {
                    RaycastHit hit;
                    var        head      = GameObject.Find("Character1_Spine1");
                    var        fromPos   = head.transform.position;
                    var        direction = new Vector3(0, 1, 0);
                    var        length    = 1.0f * transform.localScale.y;
                    // 上方向にレイを飛ばしてブロックにあたっていないか判定
                    Debug.DrawRay(fromPos, direction.normalized * length, Color.green, 1, false);
                    if (Physics.Raycast(fromPos, direction, out hit, length))
                    {
                        if (hit.collider.tag == "Block")
                        {
                            var block = hit.collider.gameObject;
                            var b     = block.GetComponent("Block") as Block;
                            b.HitBlock();
                            Velocity.y  = 0;
                            blockHit    = true;
                            jumpCounter = 100;
                        }
                    }
                }
            }
            else
            {
                jumpCounter = 0;
            }

            // 穴判定
            if (transform.position.y < -5)
            {
                if (!rule.endFlag)
                {
                    PlayerSE.PlayerSEPlay(PlayerSEManager.PLAYER_SE_LABEL.PLAYER_SE_DEAD);
                    StartCoroutine(rule.Restart());
                }
                rule.endFlag = true;
            }
        }
    }