Ejemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (gameplayManagerScript.getMissionStatus() && unhit)
     {
         // distance stuff
         float currentDistance = distance(missileObject.transform.position, transform.position);
         if (currentDistance < lowestDistance)
         {
             lowestDistance = currentDistance;
         }
         if (!distThresh1_passed && currentDistance <= distThresh1)
         {
             distThresh1_passed = true;
             myAudioSource.clip = (AudioClip)Resources.Load("Audio/dingdong1");
             myAudioSource.Play();
             gameplayManagerScript.missile_fuel_change(Mathf.RoundToInt(gameplayManagerScript.getMissileMaxFuel() * 0.05f));
         }
         if (!distThresh2_passed && currentDistance <= distThresh2)
         {
             distThresh2_passed = true;
             myAudioSource.clip = (AudioClip)Resources.Load("Audio/dingdong2");
             myAudioSource.Play();
             gameplayManagerScript.missile_HP_change(Mathf.RoundToInt(gameplayManagerScript.getMissileMaxHP() * 0.05f));
         }
     }
 }
Ejemplo n.º 2
0
 // Update is called once per frame
 void Update()
 {
     if (gameplayManagerScript.getMissionStatus() && unhit && myCollider.IsTouching(missileGameObject.GetComponent <Collider2D>()))        // hit missile
     {
         unhit = false;
         // myCollider.enabled=false;
         mySprRen.color = Color.clear;
         myAduioSource.Play();
         if (isHealthPickup || mySprRen.sprite.name.Equals("healthpickup1"))
         {
             gameplayManagerScript.missile_HP_change(Mathf.RoundToInt(gameplayManagerScript.getMissileMaxHP() * healthRestorePercent));
         }
         if (isFuelPickup || mySprRen.sprite.name.Equals("fuelpickup1"))
         {
             gameplayManagerScript.missile_fuel_change(gameplayManagerScript.getMissileMaxFuel() * fuelRestorePercent);
         }
     }
     if (!unhit)
     {
         Color currentColor = mySprRen.color;
         currentColor.a -= alphaDecreasePerSec * Time.deltaTime;
         mySprRen.color  = currentColor;
         Vector3 currentScale = transform.localScale;
         currentScale        += scaleIncreasePerSec * Vector3.one * Time.deltaTime;
         transform.localScale = currentScale;
         if (!myAduioSource.isPlaying)
         {
             Destroy(gameObject);
         }
     }
     if (!liveZoneCollider.OverlapPoint(transform.position))         // time to stop existing
     {
         Destroy(gameObject);
     }
 }
Ejemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        if (liveZoneObject == null)
        {
            liveZoneObject = GameObject.FindGameObjectWithTag("LiveZone");
        }
        if (missileObject == null)
        {
            missileObject = GameObject.FindGameObjectWithTag("Missile");
        }
        if (gameplayManagerObject == null)
        {
            gameplayManagerObject = GameObject.FindGameObjectWithTag("GameplayManager");
        }


        mySprRen              = GetComponent <SpriteRenderer>();
        myRB                  = GetComponent <Rigidbody2D>();
        myCollider            = GetComponent <BoxCollider2D>();
        myAudioSource         = GetComponent <AudioSource>();
        liveZoneCollider      = liveZoneObject.GetComponent <Collider2D>();
        gameplayManagerScript = gameplayManagerObject.GetComponent <GameplayManagement>();


        if (gameObject.name == "Helicopter" || gameObject.name == "Helicopter(Clone)" || mySprRen.sprite.name.Equals("helicopter"))
        {
            isHelicopter = true;
        }


        myRB.velocity = new Vector2(speed * gameplayManagerScript.getSpeedMult(), 0f);

        if (isHelicopter)
        {
            myRB.velocity = new Vector2(myRB.velocity.x, -(transform.position.y / transform.position.x) * Random.value * Mathf.Abs(speed));
        }

        if (gameplayManagerScript.getMissionStatus())
        {
            lowestDistance = distance(missileObject.transform.position, transform.position);
        }
    }
Ejemplo n.º 4
0
    void Update()
    {
        // went too far off screen
        if (!liveZoneObject.GetComponent <Collider2D>().OverlapPoint(transform.position))
        {
            gameplayManagerScript.missionOver();
        }



        // thrusting effects
        if (gameplayManagerScript.getMissileFuelPercentage() > 0.0f)       // fuel is not depleted
        {
            if (Input.GetButton("Fire1"))
            {
                thrustAudioSource.volume           = thrust_volume_thrusting;
                missileEmissionModule.rateOverTime = new ParticleSystem.MinMaxCurve(randomRangeVectorBounds(thrust_particle_emission_thrusting));
                missileMainModule.startSize        = new ParticleSystem.MinMaxCurve(randomRangeVectorBounds(thrust_particle_size_thrusting));
            }
            else
            {
                thrustAudioSource.volume           = thrust_volume_normal;
                missileEmissionModule.rateOverTime = new ParticleSystem.MinMaxCurve(randomRangeVectorBounds(thrust_particle_emission_normal));
                missileMainModule.startSize        = new ParticleSystem.MinMaxCurve(randomRangeVectorBounds(thrust_particle_size_normal));
            }
        }
        else
        {
            thrustAudioSource.volume           = thrust_volume_empty;
            missileEmissionModule.rateOverTime = new ParticleSystem.MinMaxCurve(randomRangeVectorBounds(thrust_particle_emission_empty));
            missileMainModule.startSize        = new ParticleSystem.MinMaxCurve(randomRangeVectorBounds(thrust_particle_size_empty));
        }


        // if not on screen
        if (!screenZoneObject.GetComponent <Collider2D>().OverlapPoint(transform.position))
        {
            offscreenArrowSprRen.enabled = true;
            Color arrowCol = offscreenArrowSprRen.color;
            arrowCol.a = (Mathf.RoundToInt(11 * Time.time)) % 2;
            offscreenArrowSprRen.color = arrowCol;
            Vector3 arrowMidwayPosition = new Vector3();
            arrowMidwayPosition.z = 0f;
            arrowMidwayPosition.x = -(Camera.main.transform.position.x - transform.position.x) * 0.40f;       // dunno why these are negative but okay
            arrowMidwayPosition.y = -(Camera.main.transform.position.y - transform.position.y) * 0.40f;
            float arrowAngle = Mathf.Rad2Deg * Mathf.Atan2(arrowMidwayPosition.y, arrowMidwayPosition.x);
            offscreenArrowObject.transform.position = arrowMidwayPosition;
            offscreenArrowObject.transform.rotation = Quaternion.Euler(0f, 0f, arrowAngle);

            if (gameplayManagerScript.getMissionStatus() && !sirenAudioSource.isPlaying)
            {
                sirenAudioSource.Play();
            }
        }
        else
        {
            offscreenArrowSprRen.enabled = false;
            sirenAudioSource.Stop();
        }



        // find out where missile should be aiming
        targetVector.x = reticleObject.transform.position.x - transform.position.x;
        targetVector.y = reticleObject.transform.position.y - transform.position.y;
        // tilt the missile in the direction of the target
        targetVector_almost.x += targetingSwiftness * (targetVector.x - targetVector_almost.x);
        targetVector_almost.y += targetingSwiftness * (targetVector.y - targetVector_almost.y);

        // get angle and make vector from it for target - don't need to thanks to Vector2.normalized property
        // targetVector_angle=Mathf.Atan2(targetVector.y,targetVector.x);
        // targetVector_angleVector.x=1.0f*Mathf.Cos(targetVector_angle);
        // targetVector_angleVector.y=1.0f*Mathf.Sin(targetVector_angle);

        // get angle for almost
        targetVector_almost_angle = Mathf.Atan2(targetVector_almost.y, targetVector_almost.x) * Mathf.Rad2Deg;
        // actually rotate sprite
        transform.rotation = Quaternion.Euler(0f, 0f, targetVector_almost_angle);
    }