Exemplo n.º 1
0
    protected CMissile CreateMissile(Vector3 dir, Color color)
    {
        CMissile tMissile = Instantiate <CMissile>(CGameDataMgr.GetInst().PFMissile, transform.position, Quaternion.identity);

        tMissile.Direction = dir.normalized;
        tMissile.SetTargetTag("tagPlayer");
        tMissile.SetColor(color);
        tMissile.SetATK(mATK);
        return(tMissile);
    }
Exemplo n.º 2
0
    private void DoMove()
    {
        float tHorizontal = Input.GetAxis("Horizontal");
        float tVertical   = Input.GetAxis("Vertical");

        mAnimator.SetInteger("aniMoveHorizontal", Mathf.CeilToInt(tHorizontal));
        if (mAnimator.GetInteger("aniMoveHorizontal") == -1)
        {
            mSpriteBody.flipX = true;
        }
        else
        {
            mSpriteBody.flipX = false;
        }
        mAnimator.SetInteger("aniMoveVertical", Mathf.CeilToInt(tVertical));


        Vector2 pos = transform.localPosition;

        pos.x = Mathf.Clamp(pos.x + (tHorizontal * mMoveSpeed * Time.deltaTime), -mMapWidth, mMapWidth);
        pos.y = Mathf.Clamp(pos.y + (tVertical * mMoveSpeed * Time.deltaTime), -mMapHeight, mMapHeight - mCollider.size.y / 2);
        transform.localPosition = pos;

        if (mFireTime >= mFireDelay)
        {
            Vector2 tFireDirection = Vector2.zero;
            tFireDirection.x = Input.GetAxisRaw("FireHorizontal");
            tFireDirection.y = Input.GetAxisRaw("FireVertical");
            if (tFireDirection.x != 0)
            {
                CMissile tMissile = Instantiate <CMissile>(CGameDataMgr.GetInst().PFMissile, mFireTransform.position, Quaternion.identity);
                tMissile.Direction = new Vector2(tFireDirection.x, 0);
                tMissile.SetTargetTag("tagEnemy");
                tMissile.SetATK(mATK);
                mFireTime = 0;
            }
            else if (tFireDirection.y != 0)
            {
                CMissile tMissile = Instantiate <CMissile>(CGameDataMgr.GetInst().PFMissile, mFireTransform.position, Quaternion.identity);
                tMissile.Direction = new Vector2(0, tFireDirection.y);
                tMissile.SetTargetTag("tagEnemy");
                tMissile.SetATK(mATK);
                mFireTime = 0;
            }
        }
        else
        {
            mFireTime += Time.deltaTime;
        }
    }