Пример #1
0
    void OnTriggerEnter(Collider collision)
    {
        //If collided with spitball, turn to goo
        if (collision.gameObject.tag == "Spitball")
        {
            Spitball spitball = collision.gameObject.GetComponent <Spitball>();
            if (spitball)
            {
                spitball.Splat();

                if (CurrentState == Enemy.State.Living)
                {
                    //Deal damage
                    m_suckable.Health -= spitball.Damage;

                    if (m_suckable.Health <= 0)
                    {
                        //Turn enemy into goo
                        Gooify();
                    }
                }
            }
        }
    }
Пример #2
0
    void Update()
    {
        if (m_startTimer > 0.0f)
        {
            m_startTimer -= Time.deltaTime;
            if (m_startTimer <= 0.0f)
            {
                PlaySFX(SFX_Pop[(int)Random.Range(0, SFX_Pop.Length)]);
                m_sprite.enabled = true;
                m_state          = State.Spawned;
            }
        }
        else
        {
            //Grab input
            Vector2 stickInputLeft  = new Vector2(Input.GetAxis("MoveX"), -Input.GetAxis("MoveY"));
            Vector2 stickInputRight = new Vector2(Input.GetAxisRaw("RotateX"), Input.GetAxisRaw("RotateY"));

            //Apply deadzone
            if (Mathf.Abs(stickInputLeft.x) < DeadZoneLeft.x)
            {
                stickInputLeft.x = 0.0f;
            }
            if (Mathf.Abs(stickInputLeft.y) < DeadZoneLeft.y)
            {
                stickInputLeft.y = 0.0f;
            }

            m_stickInputLeft  = stickInputLeft;
            m_stickInputRight = stickInputRight;

            //Apply velocity (scaled by current evolution)
            m_velocity += new Vector3(m_stickInputLeft.x * CurrentEvolution.MoveSpeedScale, -Gravity * Time.deltaTime, m_stickInputLeft.y * CurrentEvolution.MoveSpeedScale);

            //Apply drag
            m_velocity.x /= 1.0f + Drag.x * Time.deltaTime;
            m_velocity.z /= 1.0f + Drag.y * Time.deltaTime;

            m_characterController.Move(Velocity * Time.deltaTime);

            //Zero Y velocity if on floor
            if ((m_characterController.collisionFlags & CollisionFlags.Below) != 0)
            {
                m_velocity.y = 0.0f;
            }

            //Calc rotation direction
            if (m_stickInputRight.SqrMagnitude() > DeadZoneRight)
            {
                Vector2    directionVector = m_stickInputRight.normalized;
                Quaternion directionQuat   = Quaternion.FromToRotation(new Vector3(0.0f, 0.0f, -1.0f), new Vector3(-directionVector.x, 0.0f, directionVector.y));

                //Apply rotation
                transform.rotation = directionQuat;
            }

            //Fire spitballs
            m_fireTimer -= Time.deltaTime;

            if (m_fireTimer <= 0.0f && Input.GetAxis("Fire1") > DeadZoneFire)
            {
                m_fireTimer = FireTime;

                if (BulletPrefab)
                {
                    GameObject spitballObj = Instantiate(BulletPrefab, transform.position, transform.rotation) as GameObject;
                    Spitball   spitball    = spitballObj.GetComponent <Spitball>();
                    spitball.Damage        = CurrentEvolution.AttackDamage;
                    spitball.VelocityScale = CurrentEvolution.AttackVelocityScale;

                    if (!m_audioSourceSpit.isPlaying)
                    {
                        m_audioSourceSpit.clip = SFX_Spit[(int)Random.Range(0, SFX_Spit.Length)];
                        m_audioSourceSpit.Play();
                    }
                }
            }

            //Suck up goo
            if (Input.GetAxis("Fire2") > DeadZoneFire)
            {
                m_sucker.StartSuck();
            }
            else
            {
                m_sucker.EndSuck();
            }
        }
    }