Пример #1
0
 // Update is called once per frame
 void Update()
 {
     if (Vector3.Distance(player.position, transform.position) < 1 && isShow)
     {
         player.GetComponentInChildren <WeaponBag>().WeaponUpgradet();
         pool.CreateObject("WeaponGetPool", player.position, player.rotation);
         isShow = false;
     }
 }
Пример #2
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Bullet")
     {
         //普通射击
         if (other.name.Contains("BlueLaserProjectile"))
         {
             GameObject hitObj = pool.CreateObject("BulletHitPool_0", transform.position, Quaternion.identity);
             pool.MyDestory(hitObj, 0.3f);
             other.gameObject.SetActive(false);
         }
         //特殊攻击
         else if (other.name.Contains("BlueRingProjectile"))
         {
             GameObject hitObj = pool.CreateObject("BulletHitPool_1", transform.position, Quaternion.identity);
             pool.MyDestory(hitObj, 0.3f);
             other.gameObject.SetActive(false);
         }
         else if (other.name.Contains("BaseStrikeEffect"))
         {
             GameObject hitObj = pool.CreateObject("SwordHitPool_1", transform.position, Quaternion.identity);
             pool.MyDestory(hitObj, 0.3f);
         }
         else if (other.name.Contains("RedLaserBoltImpact"))
         {
             GameObject hitObj = pool.CreateObject("SwordHitPool_0", transform.position, Quaternion.identity);
             pool.MyDestory(hitObj, 0.3f);
         }
         else if (other.name.Contains("Slash04"))
         {
             GameObject hitObj = pool.CreateObject("RoundHitPool", transform.position, Quaternion.identity);
             pool.MyDestory(hitObj, 0.3f);
         }
         //敌人受伤
         OnDamage(player.attack);
     }
 }
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Building" && transform.name.Contains("BlueLaserProjectile"))
        {
            GameObject hitObj = pool.CreateObject("BulletHitPool_0", transform.position, Quaternion.identity);
            pool.MyDestory(hitObj, 0.3f);
            gameObject.SetActive(false);
        }

        if (other.tag == "Player" && transform.name.Contains("ShockwaveProjectile"))
        {
            float attackValue = GameObject.FindGameObjectWithTag("Enemy").GetComponent <EnemyState>().attack;
            other.GetComponent <PlayerState>().OnDamage(attackValue);
        }
    }
Пример #4
0
 private void Update()
 {
     if (weaponCache[GameLevel.weaponGet].activeSelf)
     {
         weaponCache[GameLevel.weaponGet].transform.Rotate(Vector3.up, Time.deltaTime * 60);
     }
     if (Vector3.Distance(player.position, transform.position) < 18 && isShow)
     {
         GameObject weapon = weaponCache[GameLevel.weaponGet];
         pool.CreateObject("WeaponGetPool", player.GetChild(0).GetChild(1).position, player.rotation);
         weaponCache[GameLevel.weaponGet.Substring(0, 1) + "Shine"].SetActive(false);
         player.GetComponentInChildren <WeaponBag>().WeaponUpgradet();
         isShow = false;
         weapon.SetActive(false);
     }
 }
Пример #5
0
    public IEnumerator SlashDely()
    {
        yield return(new WaitForSeconds(0.3f));

        GameObject slash = pool.CreateObject("SlashPool", transform.position + new Vector3(-0.5f, 1, 1.5f), transform.rotation);

        pool.MyDestory(slash, 0.4f);
    }
Пример #6
0
    // Update is called once per frame
    void Update()
    {
        //MOVEMENT
        // handle "sticking" when stopped horizontally
        if (physics.movementStopped)
        {
            targetSpeed  = 0;
            currentSpeed = 0;
        }
        if (!damaged)
        {
            //handle grounded movement
            if (physics.grounded)
            {
                amountToMove.y = 0;

                if (jumping)
                {
                    jumping = false;
                    animator.SetBool("Jumping", false);
                    animator.SetBool("Falling", false);
                }

                if (!sliding)
                {
                    if ((Input.GetAxisRaw("Vertical") < 0 && Input.GetButtonDown("Jump")) || Input.GetButtonDown("Slide"))
                    {
                        sliding = true;
                        animator.SetBool("Sliding", true);
                        //physics.SetSlideCollider(false);
                        slideStartTime = Time.time;
                    }
                }

                // Jump
                if (Input.GetButtonDown("Jump") && !sliding)
                {
                    amountToMove.y = jumpSpeed;
                    jumping        = true;
                    animator.SetBool("Jumping", true);
                }
            }

            //handle directional input
            if (!sliding)
            {
                targetSpeed  = (Input.GetAxisRaw("Horizontal") != 0) ? Mathf.Sign(Input.GetAxisRaw("Horizontal")) * speed : 0;
                currentSpeed = IncrementTowards(currentSpeed, targetSpeed, acceleration);
            }
            else
            {
                if (Time.time - slideStartTime >= slideDuration)
                {
                    // stop sliding
                    sliding = false;
                    animator.SetBool("Sliding", false);
                    //physics.SetSlideCollider(true);
                }
                else
                {
                    // move in correct direction

                    /*if (targetSpeed == 0) {
                     *  // right if facing right and left if facing left
                     *  currentSpeed = (transform.eulerAngles.y == 0) ? speed : -speed;
                     * }*/
                    currentSpeed = ((transform.eulerAngles.y == 0) ? speed : -speed) * slideSpeedMultiplier;
                }
            }

            // need to keep track of which direction the character is facing
            float facing = Mathf.Sign(targetSpeed);
            if (facing != 0 && targetSpeed != 0)
            {
                // Flip the character sprite if going left
                transform.eulerAngles = (facing < 0) ? Vector3.up * 180 : Vector3.zero;
            }

            if (invincible)
            {
                Debug.Log("invincibility check");
                //blink character to show invincibility after damage
                if (Time.time - timeDamaged <= invincibleTime)
                {
                    if ((Time.frameCount % 60) % 5 == 0)
                    {
                        sprite.enabled = (sprite.enabled) ? false : true;
                    }
                }
                else
                {
                    Debug.Log("invincibility done");
                    sprite.enabled = true;
                    invincible     = false;
                }
            }
        }
        else
        {
            // Damaged
            if (!physics.grounded)
            {
                amountToMove.y = (amountToMove.y >= 5) ? 5 : amountToMove.y;
            }
            currentSpeed = (transform.eulerAngles == Vector3.zero) ? -8.0f : 8.0f;

            if (Time.time - timeDamaged >= (invincibleTime / 5.0f))
            {
                damaged = false;
                animator.SetBool("Hit", false);
                currentSpeed = 0;
            }
        }

        animator.SetFloat("Speed", Mathf.Abs(currentSpeed));

        if (Input.GetButtonUp("Jump"))
        {
            amountToMove.y = (amountToMove.y >= 2) ? 5 : amountToMove.y;
        }
        amountToMove.x  = currentSpeed;
        amountToMove.y -= gravity * Time.deltaTime;

        //if(jumping) Debug.Log ("jump speed: " + jumpSpeed + ", negative speed: " + amountToMove.y );
        if (jumping && amountToMove.y < -5.0)
        {
            animator.SetBool("Falling", true);
        }

        physics.Move(amountToMove * Time.deltaTime);

        // FIRING
        if (Input.GetButtonDown("Fire") && GameObject.FindGameObjectsWithTag("PlayerProjectile").Length < 3 && !sliding)
        {
            // can fire anytime except when sliding
            charging = true;
            bulletPool.CreateObject(1);
            lastShotTime = Time.time;
            animator.SetBool("Shooting", true);
        }

        if (charging)
        {
            float chargeTime = Time.time - lastShotTime;
            Debug.Log("chargetime: " + chargeTime + " , chargethresh: " + chargeThreshold);
            if (Input.GetButton("Fire"))
            {
                if (chargeTime >= chargeThreshold)
                {
                    Debug.Log("FULLY CHARGED");
                    animator.SetInteger("ChargeLevel", 2);
                }
                else if (chargeTime >= (chargeThreshold / 3.0f))
                {
                    Debug.Log("HALF CHARGED");
                    animator.SetInteger("ChargeLevel", 1);
                }
            }
            else
            {
                charging = false;

                if (chargeTime >= chargeThreshold)
                {
                    bulletPool.CreateObject(2);
                    animator.SetInteger("ChargeLevel", 0);
                }
                else if (chargeTime >= chargeThreshold / 3.0f)
                {
                    bulletPool.CreateObject(3);
                    animator.SetInteger("ChargeLevel", 0);
                }
                lastShotTime = Time.time;
            }
        }
        else if (animator.GetBool("Shooting") && (Time.time - lastShotTime) >= 1.0f)
        {
            animator.SetBool("Shooting", false);
        }
    }