Esempio n. 1
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.tag == "wall")
     {
         Destroy(gameObject);
     }
     else if (other.tag == "Bullet")
     {
         BulletMove_3 bullet = other.GetComponent <BulletMove_3>();
         target = bullet.comeFrom;
         target.SendMessage("SetBig");
         got(target);
     }
     else if (other.tag == "Missile")
     {
         MissileMove missile = other.GetComponent <MissileMove>();
         target = missile.comeFrom;
         target.SendMessage("SetBig");
         got(target);
     }
     else if (other.tag == "Player")
     {
         Destroy(gameObject);
     }
 }
Esempio n. 2
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.tag == "wall")
     {
         Destroy(gameObject);
     }
     else if (other.tag == "Bullet")
     {
         bulletMove bullet = other.GetComponent <bulletMove>();
         target = bullet.comeFrom;
         target.SendMessage("SetMulti");
         got(target);
     }
     else if (other.tag == "Player")
     {
         other.transform.parent.gameObject.SendMessage("SetMulti");
         Destroy(gameObject);
     }
     else if (other.tag == "Missile")
     {
         MissileMove missile = other.GetComponent <MissileMove>();
         target = missile.comeFrom;
         target.SendMessage("SetMulti");
         got(target);
     }
 }
Esempio n. 3
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.collider.transform.tag == "Enemy")
     {
         AsteroidCollide script = collision.gameObject.GetComponent <AsteroidCollide>();
         hurtMe(script.damage, collision);
     }
     else if (collision.collider.transform.tag == "Missile")
     {
         MissileMove script = collision.gameObject.GetComponent <MissileMove>();
         hurtMe(script.damage, collision);
     }
     else if (collision.collider.transform.tag == "Boulder")
     {
         hurtMe(2, collision);
     }
 }
    void FixedUpdate()
    {
        rigid.position = new Vector3
                         (
            Mathf.Clamp(rigid.position.x, boundary1stick.xMin, boundary1stick.xMax),
            Mathf.Clamp(rigid.position.y, boundary1stick.yMin, boundary1stick.yMax),
            Mathf.Clamp(rigid.position.z, boundary1stick.zMin, boundary1stick.zMax)
                         );
        //Vector3 pos = rigid.position;

        //float v_dir = Input.GetAxis("J-V-Direct");
        //float h_dir = Input.GetAxis("J-H-Direct");
        //float v_dir = Input.GetAxis("J2-V-Direct");
        //float h_dir = Input.GetAxis("J2-H-Direct");

        //Vector3 direction = Vector3.zero;

        //direction.x = -h_dir;
        //direction.y = v_dir;

        //angle = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg;
        Quaternion rotation = Quaternion.AngleAxis(Aimtest(targetYpos), new Vector3(0f, 0f, -1f));

        //Debug.Log(Aimtest(targetYpos));
        // recoil = direction.y < 0f ? new Vector3(0f, 0f, 0f) : recoilIntensity * -direction.normalized;

        //if (direction.magnitude >= 0.5)
        //{
        transform.GetChild(activeTurret).rotation = rotation;
        LastDirection = rotation;
        //}
        //else
        //{
        //    transform.GetChild(activeTurret).rotation = LastDirection;
        //}

        MoveAnim.Play("body Animation");
        MovementSet();
        Wall.SendMessage("GetMovement", Movespeed);
        testbuff();
        if (buff_frozen)//
        {
            gameObject.transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material = ice;
            buff = 0.6f;
        }
        else
        {
            gameObject.transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material = normal;
            buff = 1f;
        }


        if (remainAmmo >= 1) //fire

        {
            isFireing = true;
        }
        else
        {
            isFireing = false;
        }

        if (isFireing)
        {
            shotCounter -= Time.deltaTime;
            if (shotCounter <= 0)
            {
                shotCounter   = timeBetweenShots;
                audioS.volume = 0.3f;

                if (isMulti)
                {
                    special -= 1;
                    BulletMove_3 newBullet1 = Instantiate(bullet, firepoint.position, firepoint.rotation) as BulletMove_3;
                    BulletMove_3 newBullet2 = Instantiate(bullet, firepoint.position, firepoint.rotation) as BulletMove_3;

                    newBullet1.gameObject.SetActive(true);
                    newBullet1.transform.Translate(new Vector3(0.2f, 0f, 0f));
                    newBullet1.transform.Rotate(new Vector3(0f, 0f, -5f));
                    newBullet1.bulletSpeed = bulletSpeed;
                    newBullet1.SendMessage("SetMulti", true);

                    newBullet2.gameObject.SetActive(true);
                    newBullet2.transform.Translate(new Vector3(-0.2f, 0f, 0f));
                    newBullet2.transform.Rotate(new Vector3(0f, 0f, 5f));
                    newBullet2.bulletSpeed = bulletSpeed;
                    newBullet2.SendMessage("SetMulti", true);

                    //CameraShaker.Instance.ShakeOnce(1.5f, 4f, 0f, 1.5f);
                    rigid.AddForce(1.5f * recoil, ForceMode.Impulse);
                    audioS.pitch = Random.Range(1f, 5f);
                    anim.Play("Double gun Animation");
                }
                else
                {
                    if (isMissile)
                    {
                        special -= 1;
                        MissileMove newMissile = Instantiate(missile, firepoint.position, firepoint.rotation) as MissileMove;
                        newMissile.gameObject.SetActive(true);
                        //CameraShaker.Instance.ShakeOnce(2f, 4f, 0f, 1.5f);
                        anim.Play("Missile Launcher Animation");
                    }
                    else
                    {
                        BulletMove_3 newBullet = Instantiate(bullet, firepoint.position, firepoint.rotation) as BulletMove_3;
                        newBullet.gameObject.SetActive(true);
                        newBullet.bulletSpeed = bulletSpeed;
                        if (isBig)
                        {
                            audioSB.pitch  = Random.Range(0.2f, 0.3f);
                            audioSB.volume = 0.5f;
                            special       -= 1;
                            newBullet.transform.localScale = new Vector3(1f, 0.1f, 1f);
                            Animator a = newBullet.GetComponent <Animator>();
                            //                           ParticleSystem p = newBullet.GetComponent<ParticleSystem>();
                            a.enabled = false;
                            newBullet.SendMessage("SetBig", true);
                            //CameraShaker.Instance.ShakeOnce(2.5f, 4f, 0f, 3f);
                            rigid.AddForce(2.0f * recoil, ForceMode.Impulse);
                        }
                        else if (isFrozen)//
                        {
                            special -= 1;
                            newBullet.SendMessage("SetFrozen", true);
                            newBullet.transform.GetChild(0).gameObject.SetActive(true);
                            newBullet.GetComponent <ParticleSystemRenderer>().material = ice;
                            //CameraShaker.Instance.ShakeOnce(1.25f, 4f, 0f, 1.5f);
                            rigid.AddForce(recoil, ForceMode.Impulse);
                            audioS.pitch = Random.Range(1f, 5f);
                        }
                        else
                        {
                            //CameraShaker.Instance.ShakeOnce(1.25f, 4f, 0f, 1.5f);
                            rigid.AddForce(recoil, ForceMode.Impulse);
                            audioS.pitch = Random.Range(1f, 5f);
                        }
                        anim.Play("Gun Animation");
                    }
                }

                SetAmmo(-1);

                if (!isMissile)
                {
                    if (isBig)
                    {
                        audioSB.Play();
                    }
                    else
                    {
                        audioS.Play();
                    }
                }
                else
                {
                    audioM.pitch = Random.Range(0.8f, 1.2f);
                    audioM.Play();
                }
            }
        }
        else
        {
            //shotCounter = 0;
            shotCounter -= Time.deltaTime;
        }
        AmmoCount.SendMessage("SetAmmo", Mathf.Floor(remainAmmo));

        float liftRatio = ((maxLife - 1) / maxLife) * remainLife / maxLife + 1f / maxLife;

        transform.GetChild(0).transform.localScale = new Vector3(1.5f * liftRatio, 0.3f, 0.5f);

        LifeCount.SendMessage("SetLife", remainLife);

        if (remainLife <= 0)
        {
            StartCoroutine(DelayTime(0.3f));
            Time.timeScale = 0.2f;
            Application.targetFrameRate = 150;
            GameObject[] score = GameObject.FindGameObjectsWithTag("Score");
            if (!SetScore)
            {
                score[0].SendMessage("rightPlus");
                SetScore = !SetScore;
            }
        }
        if (isSpecial && special <= 0)
        {
            isBig     = false;
            isMulti   = false;
            isMissile = false;
            isFrozen  = false;//
            gameObject.transform.GetChild(1).transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            this.transform.GetChild(1).GetChild(1).GetChild(1).gameObject.SetActive(false);
            UseTurret1();
            isSpecial = !isSpecial;
        }

        SpeCount.SendMessage("SetSpe", special);
    }
Esempio n. 5
0
    void FixedUpdate()
    {
        rigid.position = new Vector3
                         (
            Mathf.Clamp(rigid.position.x, boundary1stick.xMin, boundary1stick.xMax),
            Mathf.Clamp(rigid.position.y, boundary1stick.yMin, boundary1stick.yMax),
            Mathf.Clamp(rigid.position.z, boundary1stick.zMin, boundary1stick.zMax)
                         );
        //Vector3 pos = rigid.position;

        //float v_dir = Input.GetAxis("J2-V-Direct");
        //float h_dir = Input.GetAxis("J2-H-Direct");

        //Vector3 direction = Vector3.zero;


        //  Debug.Log(Aimtest(targetXpos));
        targetXpos = target.transform.position.x;

        Quaternion rotation = Quaternion.AngleAxis(Aimtest(targetXpos), new Vector3(0f, 0f, -1f));

        recoiltest(firepoint.transform.position - gameObject.transform.position);
        //L2, check if sink
        if (rigid.position.y < boundary1stick.yMin + 0.2)
        {
            remainLife = 0;
            if (!hasFall)
            {
                waterSound.Play();
                waterSplatter = GameObject.Find("FX_WaterSplatter");
                GameObject     newSplatters      = Instantiate(waterSplatter, transform.position, new Quaternion()) as GameObject;
                ParticleSystem SplattersParticle = newSplatters.GetComponent <ParticleSystem>();
                var            main = SplattersParticle.main;
                main.startSize  = 0.5f;
                main.startSpeed = 5f;
                Destroy(newSplatters, 1.5f);
                hasFall = !hasFall;
            }
        }
        //

        // recoil = direction.y < 0f ? new Vector3(0f, 0f, 0f) : recoilIntensity * -direction.normalized;
        transform.GetChild(activeTurret).rotation = rotation;
        LastDirection = rotation;


        MovementSet();
        if (Movespeed != 0)
        {
            MoveAnim.Play("body Animation");
        }
        testbuff();
        if (buff_frozen)//
        {
            gameObject.transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material = ice;
            buff = 0.6f;
        }
        else
        {
            gameObject.transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material = normal;
            buff = 1f;
        }

        //L2, velocity modified here
        rigid.velocity = new Vector3(buff * Accelrate * Movespeed + floeVelocity, rigid.velocity.y, 0f);
        //

        if (remainAmmo >= 1)  //fire

        {
            isFireing = true;
        }
        else
        {
            isFireing = false;
        }

        if (isFireing)
        {
            shotCounter -= Time.deltaTime;
            if (shotCounter <= 0)
            {
                shotCounter   = timeBetweenShots;
                audioS.volume = 0.3f;

                if (isMulti)
                {
                    special -= 1;
                    bulletMove newBullet1 = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove;
                    bulletMove newBullet2 = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove;

                    newBullet1.gameObject.SetActive(true);
                    newBullet1.transform.Translate(new Vector3(0.2f, 0f, 0f));
                    newBullet1.transform.Rotate(new Vector3(0f, 0f, -5f));
                    newBullet1.bulletSpeed = bulletSpeed;
                    newBullet1.SendMessage("SetMulti", true);

                    newBullet2.gameObject.SetActive(true);
                    newBullet2.transform.Translate(new Vector3(-0.2f, 0f, 0f));
                    newBullet2.transform.Rotate(new Vector3(0f, 0f, 5f));
                    newBullet2.bulletSpeed = bulletSpeed;
                    newBullet2.SendMessage("SetMulti", true);

                    //CameraShaker.Instance.ShakeOnce(1.5f, 4f, 0f, 1.5f);
                    //rigid.AddForce(1.5f * recoil, ForceMode.Impulse);
                    if (updownrecoil == 0)
                    {
                        rigid.AddForce(1.5f * up, ForceMode.Impulse);
                    }
                    else if (updownrecoil == 1)
                    {
                        rigid.AddForce(1.5f * down, ForceMode.Impulse);
                    }
                    audioS.pitch = Random.Range(1f, 5f);
                    anim.Play("Double gun Animation");
                }
                else
                {
                    if (isMissile)
                    {
                        special -= 1;
                        MissileMove newMissile = Instantiate(missile, firepoint.position, firepoint.rotation) as MissileMove;
                        newMissile.gameObject.SetActive(true);
                        //CameraShaker.Instance.ShakeOnce(2f, 4f, 0f, 1.5f);
                        anim.Play("Missile Launcher Animation");
                    }
                    else
                    {
                        bulletMove newBullet = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove;
                        newBullet.gameObject.SetActive(true);
                        newBullet.bulletSpeed = bulletSpeed;
                        if (isBig)
                        {
                            audioSB.pitch  = Random.Range(0.2f, 0.3f);
                            audioSB.volume = 0.5f;
                            special       -= 1;
                            newBullet.transform.localScale = new Vector3(1f, 0.08f, 1f);
                            Animator a = newBullet.GetComponent <Animator>();
                            //                           ParticleSystem p = newBullet.GetComponent<ParticleSystem>();
                            a.enabled = false;
                            newBullet.SendMessage("SetBig", true);
                            //CameraShaker.Instance.ShakeOnce(2.5f, 4f, 0f, 3f);
                            // rigid.AddForce(2.0f * recoil, ForceMode.Impulse);
                            if (updownrecoil == 0)
                            {
                                rigid.AddForce(2 * up, ForceMode.Impulse);
                            }
                            else if (updownrecoil == 1)
                            {
                                rigid.AddForce(2 * down, ForceMode.Impulse);
                            }
                        }
                        else if (isFrozen)//
                        {
                            special -= 1;
                            newBullet.SendMessage("SetFrozen", true);
                            newBullet.transform.GetChild(0).gameObject.SetActive(true);
                            newBullet.GetComponent <ParticleSystemRenderer>().material = ice;
                            //CameraShaker.Instance.ShakeOnce(1.25f, 4f, 0f, 1.5f);
                            if (updownrecoil == 0)
                            {
                                rigid.AddForce(up, ForceMode.Impulse);
                            }
                            else if (updownrecoil == 1)
                            {
                                rigid.AddForce(down, ForceMode.Impulse);
                            }
                            audioS.pitch = Random.Range(1f, 5f);
                        }
                        else
                        {
                            //CameraShaker.Instance.ShakeOnce(1.25f, 4f, 0f, 1.5f);
                            // rigid.AddForce(recoil, ForceMode.Impulse);
                            if (updownrecoil == 0)
                            {
                                rigid.AddForce(up, ForceMode.Impulse);
                            }
                            else if (updownrecoil == 1)
                            {
                                rigid.AddForce(down, ForceMode.Impulse);
                            }
                            audioS.pitch = Random.Range(1f, 5f);
                        }
                    }
                    anim.Play("Gun Animation");
                }

                SetAmmo(-1);

                if (!isMissile)
                {
                    if (isBig)
                    {
                        audioSB.Play();
                    }
                    else
                    {
                        audioS.Play();
                    }
                }
                else
                {
                    audioM.pitch = Random.Range(0.8f, 1.2f);
                    audioM.Play();
                }

                //L2, add modify floe speed effect
                floe.SendMessage("UpdateVelocity", -Mathf.Sin(angle / Mathf.Rad2Deg) * maxFloeImpact);
                //
            }
        }
        else
        {
            //shotCounter = 0;
            shotCounter -= Time.deltaTime;
        }
        AmmoCount.SendMessage("SetAmmo", Mathf.Floor(remainAmmo));

        float liftRatio = ((maxLife - 1) / maxLife) * remainLife / maxLife + 1f / maxLife;

        transform.GetChild(0).transform.localScale = new Vector3(1.5f * liftRatio, 0.3f, 0.5f);

        LifeCount.SendMessage("SetLife", remainLife);

        if (remainLife <= 0)
        {
            //L2, stop update velocity from floe
            floe.SendMessage("PlayerDie");
            //

            StartCoroutine(DelayTime(0.3f));
            Time.timeScale = 0.2f;
            Application.targetFrameRate = 150;
            GameObject[] score = GameObject.FindGameObjectsWithTag("Score");
            if (!SetScore)
            {
                score[0].SendMessage("rightPlus");
                SetScore = !SetScore;
            }
        }
        if (isSpecial && special <= 0)
        {
            isBig     = false;
            isMulti   = false;
            isMissile = false;
            isFrozen  = false;//
            gameObject.transform.GetChild(1).transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            this.transform.GetChild(1).GetChild(1).GetChild(1).gameObject.SetActive(false);
            UseTurret1();
            isSpecial = !isSpecial;
        }

        SpeCount.SendMessage("SetSpe", special);
    }
Esempio n. 6
0
    void FixedUpdate()
    {
        Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        rigid.position = new Vector3
                         (
            Mathf.Clamp(rigid.position.x, boundary1mouse.xMin, boundary1mouse.xMax),
            Mathf.Clamp(rigid.position.y, boundary1mouse.yMin, boundary1mouse.yMax),
            Mathf.Clamp(rigid.position.z, boundary1mouse.zMin, boundary1mouse.zMax)
                         );
        Vector3 pos       = rigid.position;
        Vector3 direction = mousePos - pos;

        angle = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg;
        Quaternion rotation = Quaternion.AngleAxis(angle, new Vector3(0f, 0f, -1f));

        transform.GetChild(activeTurret).rotation = rotation;

        float h_axis = Input.GetAxis("Horizontal");

        //recoil = direction.y < 0f ? new Vector3(0f, 0f, 0f) : recoilIntensity * -direction.normalized;
        recoiltest(firepoint.transform.position - gameObject.transform.position);

        testbuff();
        if (buff_frozen)//
        {
            gameObject.transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material = ice;
            buff = 0.6f;
        }
        else
        {
            gameObject.transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material = normal;
            buff = 1f;
        }
        rigid.velocity = new Vector3(buff * Accelrate * h_axis, rigid.velocity.y, 0f);
        if (h_axis != 0)
        {
            MoveAnim.Play("body Animation");
        }

        if ((Input.GetMouseButton(0) || Input.GetKey(KeyCode.Space)) && remainAmmo >= 1) //fire
        {
            isFireing = true;
        }
        else
        {
            isFireing = false;
        }

        if (isFireing)
        {
            shotCounter -= Time.deltaTime;
            if (shotCounter <= 0)
            {
                shotCounter   = timeBetweenShots;
                audioS.volume = 0.3f;

                if (isMulti)
                {
                    special -= 1;
                    bulletMove newBullet1 = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove;
                    bulletMove newBullet2 = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove;

                    newBullet1.gameObject.SetActive(true);
                    newBullet1.transform.Translate(new Vector3(0.2f, 0f, 0f));
                    newBullet1.transform.Rotate(new Vector3(0f, 0f, -5f));
                    newBullet1.bulletSpeed = bulletSpeed;
                    newBullet1.SendMessage("SetMulti", true);

                    newBullet2.gameObject.SetActive(true);
                    newBullet2.transform.Translate(new Vector3(-0.2f, 0f, 0f));
                    newBullet2.transform.Rotate(new Vector3(0f, 0f, 5f));
                    newBullet2.bulletSpeed = bulletSpeed;
                    newBullet2.SendMessage("SetMulti", true);

                    //CameraShaker.Instance.ShakeOnce(1.5f, 4f, 0f, 1.5f);
                    //rigid.AddForce(1.5f * recoil, ForceMode.Impulse);
                    if (updownrecoil == 0)
                    {
                        rigid.AddForce(1.5f * left, ForceMode.Impulse);
                    }
                    else if (updownrecoil == 1)
                    {
                        rigid.AddForce(1.5f * right, ForceMode.Impulse);
                    }
                    audioS.pitch = Random.Range(1f, 5f);
                    anim.Play("Double gun Animation");
                }
                else
                {
                    if (isMissile)
                    {
                        special -= 1;
                        MissileMove newMissile = Instantiate(missile, firepoint.position, firepoint.rotation) as MissileMove;
                        newMissile.gameObject.SetActive(true);
                        //CameraShaker.Instance.ShakeOnce(2f, 4f, 0f, 1.5f);
                        anim.Play("Missile Launcher Animation");
                    }
                    else
                    {
                        bulletMove newBullet = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove;
                        newBullet.gameObject.SetActive(true);
                        newBullet.bulletSpeed = bulletSpeed;
                        if (isBig)
                        {
                            audioSB.pitch  = Random.Range(0.2f, 0.3f);
                            audioSB.volume = 0.5f;
                            special       -= 1;
                            newBullet.transform.localScale = new Vector3(1f, 0.1f, 1f);
                            Animator a = newBullet.GetComponent <Animator>();
                            //                           ParticleSystem p = newBullet.GetComponent<ParticleSystem>();
                            a.enabled = false;
                            newBullet.SendMessage("SetBig", true);
                            //CameraShaker.Instance.ShakeOnce(2.5f, 4f, 0f, 3f);
                            //rigid.AddForce(2.0f * recoil, ForceMode.Impulse);
                            if (updownrecoil == 0)
                            {
                                rigid.AddForce(2 * left, ForceMode.Impulse);
                            }
                            else if (updownrecoil == 1)
                            {
                                rigid.AddForce(2 * right, ForceMode.Impulse);
                            }
                        }
                        else if (isFrozen)//
                        {
                            special -= 1;
                            newBullet.SendMessage("SetFrozen", true);
                            newBullet.transform.GetChild(0).gameObject.SetActive(true);
                            newBullet.GetComponent <ParticleSystemRenderer>().material = ice;
                            //CameraShaker.Instance.ShakeOnce(1.25f, 4f, 0f, 1.5f);
                            //rigid.AddForce(recoil, ForceMode.Impulse);
                            if (updownrecoil == 0)
                            {
                                rigid.AddForce(left, ForceMode.Impulse);
                            }
                            else if (updownrecoil == 1)
                            {
                                rigid.AddForce(right, ForceMode.Impulse);
                            }
                            audioS.pitch = Random.Range(1f, 5f);
                        }
                        else
                        {
                            //CameraShaker.Instance.ShakeOnce(1.25f, 4f, 0f, 1.5f);
                            audioS.pitch = Random.Range(1f, 5f);
                            //rigid.AddForce(recoil, ForceMode.Impulse);
                            if (updownrecoil == 0)
                            {
                                rigid.AddForce(left, ForceMode.Impulse);
                            }
                            else if (updownrecoil == 1)
                            {
                                rigid.AddForce(right, ForceMode.Impulse);
                            }
                        }
                        anim.Play("Gun Animation");
                    }
                }

                SetAmmo(-1);
                if (!isMissile)
                {
                    if (isBig)
                    {
                        audioSB.Play();
                    }
                    else
                    {
                        audioS.Play();
                    }
                }
                else
                {
                    audioM.pitch = Random.Range(0.8f, 1.2f);
                    audioM.Play();
                }
            }
        }
        else
        {
            //shotCounter = 0;
            shotCounter -= Time.deltaTime;
        }
        AmmoCount.SendMessage("SetAmmo", Mathf.Floor(remainAmmo));

        float liftRatio = ((maxLife - 1) / maxLife) * remainLife / maxLife + 1f / maxLife;

        transform.GetChild(0).transform.localScale = new Vector3(1.5f * liftRatio, 0.3f, 0.5f);

        LifeCount.SendMessage("SetLife", remainLife);

        if (remainLife <= 0)
        {
            StartCoroutine(DelayTime(0.3f));
            Time.timeScale = 0.2f;
            GameObject[] score = GameObject.FindGameObjectsWithTag("Score");
            if (!SetScore)
            {
                score[0].SendMessage("rightPlus");
                SetScore = !SetScore;
            }
        }

        if (isSpecial && special <= 0)
        {
            isBig     = false;
            isMulti   = false;
            isMissile = false;
            isFrozen  = false;//
            gameObject.transform.GetChild(1).transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            this.transform.GetChild(1).GetChild(1).GetChild(1).gameObject.SetActive(false);
            UseTurret1();
            isSpecial = !isSpecial;
        }

        SpeCount.SendMessage("SetSpe", special);
    }
Esempio n. 7
0
    void FixedUpdate()
    {
        //set recoil angle
        recoil = 360 - transform.localRotation.eulerAngles.x;
        float posY = 1 * Mathf.Sin(recoil * Mathf.Deg2Rad);
        float posX = 1 * Mathf.Cos(recoil * Mathf.Deg2Rad);

        up   = new Vector3(-posX, -posY, 0f).normalized *recoilIntensity;
        down = new Vector3(posX, posY, 0).normalized *recoilIntensity;

        rigid.position = new Vector3
                         (
            Mathf.Clamp(rigid.position.x, boundary1stick.xMin, boundary1stick.xMax),
            Mathf.Clamp(rigid.position.y, boundary1stick.yMin, boundary1stick.yMax),
            Mathf.Clamp(rigid.position.z, boundary1stick.zMin, boundary1stick.zMax)
                         );
        Vector3 pos = rigid.position;

        float v_dir = Input.GetAxis("J2-V-Direct");
        float h_dir = Input.GetAxis("J2-H-Direct");

        Vector3 direction = Vector3.zero;

        direction.x = -h_dir;
        direction.y = v_dir;

        angle = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg;
        Quaternion rotation = Quaternion.AngleAxis(angle, new Vector3(0f, 0f, -1f));

        recoiltest();

        if (direction.magnitude >= 0.5)
        {
            transform.GetChild(activeTurret).rotation = rotation;
            LastDirection = rotation;
        }
        else
        {
            transform.GetChild(activeTurret).rotation = LastDirection;
        }

        float h_axis = Input.GetAxis("J2-Horizontal");

        if (h_axis != 0)
        {
            MoveAnim.Play("body Animation");
        }

        testbuff();
        if (buff_frozen)//
        {
            gameObject.transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material = ice;
            buff = 0.6f;
        }
        else
        {
            gameObject.transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material = normal;
            buff = 1f;
        }

        rigid.velocity = new Vector3(buff * Accelrate * h_axis, rigid.velocity.y > 0f ? 0f : rigid.velocity.y, 0f);
        if (Input.GetAxis("J2-Fire2") < 0 && remainAmmo >= 1) //fire

        {
            isFireing = true;
        }
        else
        {
            isFireing = false;
        }

        if (isFireing)
        {
            shotCounter -= Time.deltaTime;
            if (shotCounter <= 0)
            {
                shotCounter   = timeBetweenShots;
                audioS.volume = 0.3f;

                if (isMulti)
                {
                    special -= 1;
                    bulletMove newBullet1 = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove;
                    bulletMove newBullet2 = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove;

                    newBullet1.gameObject.SetActive(true);
                    newBullet1.transform.Translate(new Vector3(0.2f, 0f, 0f));
                    newBullet1.transform.Rotate(new Vector3(0f, 0f, -5f));
                    newBullet1.bulletSpeed = bulletSpeed;
                    newBullet1.SendMessage("SetMulti", true);

                    newBullet2.gameObject.SetActive(true);
                    newBullet2.transform.Translate(new Vector3(-0.2f, 0f, 0f));
                    newBullet2.transform.Rotate(new Vector3(0f, 0f, 5f));
                    newBullet2.bulletSpeed = bulletSpeed;
                    newBullet2.SendMessage("SetMulti", true);

                    //CameraShaker.Instance.ShakeOnce(1.5f, 4f, 0f, 1.5f);
                    if (updownrecoil == 0)
                    {
                        rigid.AddForce(1.5f * up, ForceMode.Impulse);
                    }
                    else if (updownrecoil == 1)
                    {
                        rigid.AddForce(1.5f * down, ForceMode.Impulse);
                    }
                    audioS.pitch = Random.Range(1f, 5f);
                    anim.Play("Double gun Animation");
                }
                else
                {
                    if (isMissile)
                    {
                        special -= 1;
                        MissileMove newMissile = Instantiate(missile, firepoint.position, firepoint.rotation) as MissileMove;
                        newMissile.gameObject.SetActive(true);
                        //CameraShaker.Instance.ShakeOnce(2f, 4f, 0f, 1.5f);
                        anim.Play("Missile Launcher Animation");
                    }
                    else
                    {
                        bulletMove newBullet = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove;
                        newBullet.gameObject.SetActive(true);
                        newBullet.bulletSpeed = bulletSpeed;
                        if (isBig)
                        {
                            audioSB.pitch  = Random.Range(0.2f, 0.3f);
                            audioSB.volume = 0.5f;
                            special       -= 1;
                            newBullet.transform.localScale = new Vector3(1f, 1f, 1f);
                            Animator a = newBullet.GetComponent <Animator>();
                            //                           ParticleSystem p = newBullet.GetComponent<ParticleSystem>();
                            a.enabled = false;
                            newBullet.SendMessage("SetBig", true);
                            //CameraShaker.Instance.ShakeOnce(2.5f, 4f, 0f, 3f);
                            if (updownrecoil == 0)
                            {
                                rigid.AddForce(2 * up, ForceMode.Impulse);
                            }
                            else if (updownrecoil == 1)
                            {
                                rigid.AddForce(2 * down, ForceMode.Impulse);
                            }
                        }
                        else if (isFrozen)//
                        {
                            special -= 1;
                            newBullet.SendMessage("SetFrozen", true);
                            newBullet.transform.GetChild(0).gameObject.SetActive(true);
                            newBullet.GetComponent <ParticleSystemRenderer>().material = ice;
                            //CameraShaker.Instance.ShakeOnce(1.25f, 4f, 0f, 1.5f);
                            if (updownrecoil == 0)
                            {
                                rigid.AddForce(up, ForceMode.Impulse);
                            }
                            else if (updownrecoil == 1)
                            {
                                rigid.AddForce(down, ForceMode.Impulse);
                            }
                            audioS.pitch = Random.Range(1f, 5f);
                        }
                        else
                        {
                            //CameraShaker.Instance.ShakeOnce(1.25f, 4f, 0f, 1.5f);
                            if (updownrecoil == 0)
                            {
                                rigid.AddForce(up, ForceMode.Impulse);
                            }
                            else if (updownrecoil == 1)
                            {
                                rigid.AddForce(down, ForceMode.Impulse);
                            }
                            audioS.pitch = Random.Range(1f, 5f);
                        }
                        anim.Play("Gun Animation");
                    }
                }

                SetAmmo(-1);

                if (!isMissile)
                {
                    if (isBig)
                    {
                        audioSB.Play();
                    }
                    else
                    {
                        audioS.Play();
                    }
                }
                else
                {
                    audioM.pitch = Random.Range(0.8f, 1.2f);
                    audioM.Play();
                }
            }
        }
        else
        {
            //shotCounter = 0;
            shotCounter -= Time.deltaTime;
        }
        AmmoCount.SendMessage("SetAmmo", Mathf.Floor(remainAmmo));

        float liftRatio = ((maxLife - 1) / maxLife) * remainLife / maxLife + 1f / maxLife;

        transform.GetChild(0).transform.localScale = new Vector3(1.5f * liftRatio, 0.3f, 0.5f);

        LifeCount.SendMessage("SetLife", remainLife);

        if (remainLife <= 0)
        {
            StartCoroutine(DelayTime(0.3f));
            Time.timeScale = 0.2f;
            Application.targetFrameRate = 150;
            GameObject[] score = GameObject.FindGameObjectsWithTag("Score");
            if (!SetScore)
            {
                score[0].SendMessage("rightPlus");
                SetScore = !SetScore;
            }
        }
        if (isSpecial && special <= 0)
        {
            isBig     = false;
            isMulti   = false;
            isMissile = false;
            isFrozen  = false;//
            gameObject.transform.GetChild(1).transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            this.transform.GetChild(1).GetChild(1).GetChild(1).gameObject.SetActive(false);
            UseTurret1();
            isSpecial = !isSpecial;
        }

        SpeCount.SendMessage("SetSpe", special);
    }
Esempio n. 8
0
    public override void AgentAction(float[] vectorAction, string textAction)
    {
        if (resetAgent == true)
        {
            //AddReward(-5f);
            Done();
        }

        float targetCurrentLife = GameObject.Find("Player1").GetComponent <ControllerP1_AITEST>().remainLife;

        if (targetCurrentLife < targetLife)
        {
            AddReward(targetLife - targetCurrentLife);
            targetLife = targetCurrentLife;
        }
        else
        {
            targetLife = targetCurrentLife;
        }

        /*
         * if (remainLife < lifeCount)
         * {
         *  AddReward(remainLife - lifeCount);
         *  lifeCount = remainLife;
         * }
         */
        rigid.position = new Vector3
                         (
            Mathf.Clamp(rigid.position.x, boundary2stick.xMin, boundary2stick.xMax),
            Mathf.Clamp(rigid.position.y, boundary2stick.yMin, boundary2stick.yMax),
            Mathf.Clamp(rigid.position.z, boundary2stick.zMin, boundary2stick.zMax)
                         );
        //Vector3 pos = rigid.position;
        //Vector3 direction = mousePos - pos;
        //angle = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg;
        //Quaternion rotation = Quaternion.AngleAxis(vectorAction[1], new Vector3(0f, 0f, -1f));

        float v_dir = vectorAction[1];
        float h_dir = vectorAction[2];

        Vector3 direction = Vector3.zero;

        direction.x = -h_dir;
        direction.y = v_dir;

        angle = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg;
        Quaternion rotation = Quaternion.AngleAxis(angle, new Vector3(0f, 0f, -1f));

        transform.GetChild(activeTurret).rotation = rotation;
        //AddReward(1f / 3000f);

        if (isGrounded == true)
        {
            h_axis = vectorAction[3];
        }
        else
        {
            h_axis = 0;
        }

        if (h_axis != 0)
        {
            MoveAnim.Play("body Animation");
            //AddReward(1f / 3000f);
        }
        else
        {
            //AddReward(-1f / 3000f);
        }

        //recoil = direction.y < 0f ? new Vector3(0f, 0f, 0f) : recoilIntensity * -direction.normalized;
        recoiltest(firepoint.transform.position - gameObject.transform.position);

        testbuff();
        if (buff_frozen)//
        {
            gameObject.transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material = ice;
            buff = 0.6f;
        }
        else
        {
            gameObject.transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material = normal;
            buff = 1f;
        }
        rigid.velocity = new Vector3(buff * Accelrate * h_axis, rigid.velocity.y, 0f);
        rigid.AddForce(Vector3.right * wind * 100);

        if ((vectorAction[0] < 0) && remainAmmo >= 1) //fire
        {
            isFireing = true;
            //AddReward(1f / 3000f);
        }
        else
        {
            isFireing = false;
            //AddReward(-1f / 3000f);
        }

        if (isFireing)
        {
            shotCounter -= Time.deltaTime;
            if (shotCounter <= 0)
            {
                shotCounter   = timeBetweenShots;
                audioS.volume = 0.3f;
                //AddReward(1f / 3000f);

                if (isMulti)
                {
                    special -= 1;
                    bulletMove newBullet1 = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove;
                    bulletMove newBullet2 = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove;

                    newBullet1.gameObject.SetActive(true);
                    newBullet1.transform.Translate(new Vector3(0.2f, 0f, 0f));
                    newBullet1.transform.Rotate(new Vector3(0f, 0f, -5f));
                    newBullet1.bulletSpeed = bulletSpeed;
                    newBullet1.SendMessage("SetMulti", true);

                    newBullet2.gameObject.SetActive(true);
                    newBullet2.transform.Translate(new Vector3(-0.2f, 0f, 0f));
                    newBullet2.transform.Rotate(new Vector3(0f, 0f, 5f));
                    newBullet2.bulletSpeed = bulletSpeed;
                    newBullet2.SendMessage("SetMulti", true);

                    //CameraShaker.Instance.ShakeOnce(1.5f, 4f, 0f, 1.5f);
                    //rigid.AddForce(1.5f * recoil, ForceMode.Impulse);
                    if (updownrecoil == 0)
                    {
                        rigid.AddForce(1.5f * left, ForceMode.Impulse);
                    }
                    else if (updownrecoil == 1)
                    {
                        rigid.AddForce(1.5f * right, ForceMode.Impulse);
                    }
                    audioS.pitch = Random.Range(1f, 5f);
                    anim.Play("Double gun Animation");
                }
                else
                {
                    if (isMissile)
                    {
                        special -= 1;
                        MissileMove newMissile = Instantiate(missile, firepoint.position, firepoint.rotation) as MissileMove;
                        newMissile.gameObject.SetActive(true);
                        //CameraShaker.Instance.ShakeOnce(2f, 4f, 0f, 1.5f);
                        anim.Play("Missile Launcher Animation");
                    }
                    else
                    {
                        bulletMove newBullet = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove;
                        newBullet.gameObject.SetActive(true);
                        newBullet.bulletSpeed = bulletSpeed;
                        if (isBig)
                        {
                            audioSB.pitch  = Random.Range(0.2f, 0.3f);
                            audioSB.volume = 0.5f;
                            special       -= 1;
                            newBullet.transform.localScale = new Vector3(1f, 0.1f, 1f);
                            Animator a = newBullet.GetComponent <Animator>();
                            //                           ParticleSystem p = newBullet.GetComponent<ParticleSystem>();
                            a.enabled = false;
                            newBullet.SendMessage("SetBig", true);
                            //CameraShaker.Instance.ShakeOnce(2.5f, 4f, 0f, 3f);
                            //rigid.AddForce(2.0f * recoil, ForceMode.Impulse);
                            if (updownrecoil == 0)
                            {
                                rigid.AddForce(2 * left, ForceMode.Impulse);
                            }
                            else if (updownrecoil == 1)
                            {
                                rigid.AddForce(2 * right, ForceMode.Impulse);
                            }
                        }
                        else if (isFrozen)//
                        {
                            special -= 1;
                            newBullet.SendMessage("SetFrozen", true);
                            newBullet.transform.GetChild(0).gameObject.SetActive(true);
                            newBullet.GetComponent <ParticleSystemRenderer>().material = ice;
                            //CameraShaker.Instance.ShakeOnce(1.25f, 4f, 0f, 1.5f);
                            //rigid.AddForce(recoil, ForceMode.Impulse);
                            if (updownrecoil == 0)
                            {
                                rigid.AddForce(left, ForceMode.Impulse);
                            }
                            else if (updownrecoil == 1)
                            {
                                rigid.AddForce(right, ForceMode.Impulse);
                            }
                            audioS.pitch = Random.Range(1f, 5f);
                        }
                        else
                        {
                            //CameraShaker.Instance.ShakeOnce(1.25f, 4f, 0f, 1.5f);
                            audioS.pitch = Random.Range(1f, 5f);
                            //rigid.AddForce(recoil, ForceMode.Impulse);
                            if (updownrecoil == 0)
                            {
                                rigid.AddForce(left, ForceMode.Impulse);
                            }
                            else if (updownrecoil == 1)
                            {
                                rigid.AddForce(right, ForceMode.Impulse);
                            }
                        }
                        anim.Play("Gun Animation");
                    }
                }

                SetAmmo(-1);
                if (!isMissile)
                {
                    if (isBig)
                    {
                        audioSB.Play();
                    }
                    else
                    {
                        audioS.Play();
                    }
                }
                else
                {
                    audioM.pitch = Random.Range(0.8f, 1.2f);
                    audioM.Play();
                }
            }
        }
        else
        {
            //shotCounter = 0;
            shotCounter -= Time.deltaTime;
        }
        AmmoCount.SendMessage("SetAmmo", Mathf.Floor(remainAmmo));

        float liftRatio = ((maxLife - 1) / maxLife) * remainLife / maxLife + 1f / maxLife;

        transform.GetChild(0).transform.localScale = new Vector3(1.5f * liftRatio, 0.3f, 0.5f);

        LifeCount.SendMessage("SetLife", remainLife);

        if (remainLife <= 0)
        {
            //StartCoroutine(DelayTime(0.3f));
            //Time.timeScale = 0.2f;

            /*
             * GameObject[] score = GameObject.FindGameObjectsWithTag("Score");
             * if (!SetScore)
             * {
             *  score[0].SendMessage("leftPlus");
             *  SetScore = !SetScore;
             * }
             */
            remainLife = maxLife;
            Done();
        }

        if (isSpecial && special <= 0)
        {
            isBig     = false;
            isMulti   = false;
            isMissile = false;
            isFrozen  = false;//
            gameObject.transform.GetChild(1).transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            this.transform.GetChild(1).GetChild(1).GetChild(1).gameObject.SetActive(false);
            UseTurret1();
            isSpecial = !isSpecial;
        }

        SpeCount.SendMessage("SetSpe", special);
    }