示例#1
0
    // Use this for initialization
    void Start()
    {
        // set time for how long sword exists
        swordTime = Time.time + 0.1f;

        // get player two health script
        playerOne      = GameObject.Find("Player 1");
        P1HealthScript = playerOne.GetComponent <PlayerOneHealth>();
    }
示例#2
0
    void Start()
    {
        // get rigid body component
        bulletMove = GetComponent <Rigidbody2D>();

        // get script for player one health
        playerTwo       = GameObject.Find("Player 2");
        P2ControlScript = playerTwo.GetComponent <PlayerTwo>();

        // get script for player two health
        playerOne      = GameObject.Find("Player 1");
        P1HealthScript = playerOne.GetComponent <PlayerOneHealth>();

        // move bullet to the left
        if (P2ControlScript.bulletLeft)
        {
            // bullet moving left
            bulletMove.velocity = new Vector3(-bulletSpeed, 0, 0);
        }

        // move bullet ot the right
        else if (P2ControlScript.bulletRight)
        {
            // bullet moving right
            bulletMove.velocity = new Vector3(bulletSpeed, 0, 0);
        }

        // move bullet diagonally right and up
        else if (P2ControlScript.bulletTopRight)
        {
            // bullet moving right
            bulletMove.velocity = new Vector3(bulletSpeed, bulletSpeed, 0);
        }

        // move bullet diagonally left and up
        else if (P2ControlScript.bulletTopLeft)
        {
            // bullet moving right
            bulletMove.velocity = new Vector3(-bulletSpeed, bulletSpeed, 0);
        }

        // move bullet diagonally right and down
        else if (P2ControlScript.bulletBottomRight)
        {
            // bullet moving right
            bulletMove.velocity = new Vector3(bulletSpeed, -bulletSpeed, 0);
        }

        // move bullet diagonally left and down
        else if (P2ControlScript.bulletBottomLeft)
        {
            // bullet moving right
            bulletMove.velocity = new Vector3(-bulletSpeed, -bulletSpeed, 0);
        }
    }
示例#3
0
        public override bool Fire(Vector3 position, Vector3 direction, float range, int ignoreLayer)
        {
            bool returnValue = false;

            CurrentShootInverval += Time.deltaTime;
            RaycastHit hit;

            // Fire towards player
            if (CurrentShootInverval > ShootRate && Physics.Raycast(position, direction, out hit, range, ignoreLayer))
            {
                sniperFireSound.Play();
                if (hit.collider.tag == "PlayerOne")
                {
                    Debug.Log("Player one shot");
                    if (PlayerOneHealth.DeductHP(Damage))
                    {
                        returnValue = true;
                    }
                    else
                    {
                        playerOneSlow.ApplyGeneralSlow(0.0f, 8.0f, 0.1f, speedPenalty);
                        HitFlash.FlashCamera(1);
                    }
                }
                else if (hit.collider.tag == "PlayerTwo")
                {
                    Debug.Log("Player two shot");
                    if (PlayerTwoHealth.DeductHP(Damage))
                    {
                        returnValue = true;
                    }
                    else
                    {
                        playerTwoSlow.ApplyGeneralSlow(0.0f, 8.0f, 0.1f, speedPenalty);
                        HitFlash.FlashCamera(2);
                    }
                }
                CurrentShootInverval -= ShootRate;
            }
            return(returnValue);
        }
示例#4
0
 void OnTriggerEnter2D(Collider2D hitInfo)
 {
     if (hitInfo.gameObject.CompareTag("Player"))
     {
         PlayerOneHealth health = hitInfo.GetComponent <PlayerOneHealth>();
         if (health != null)
         {
             health.TakeDamage(damage);
             damageSource.PlayOneShot(damageSound, 1.0f);
         }
         Destroy(gameObject);
     }
     else if (hitInfo.gameObject.CompareTag("Player2"))
     {
         PlayerTwoHealth health = hitInfo.GetComponent <PlayerTwoHealth>();
         if (health != null)
         {
             health.TakeDamage(damage);
             damageSource.PlayOneShot(damageSound, 1.0f);
         }
         Destroy(gameObject);
     }
 }
示例#5
0
        public override bool Fire(Vector3 position, Vector3 direction, float range, int ignoreLayer)
        {
            bool returnValue = false;

            CurrentShootInverval += Time.deltaTime;
            muzzleFlashInterval  += Time.deltaTime;

            // Turn off muzzle flash light
            if (muzzleFlashInterval > 0.05f)
            {
                foreach (GameObject muzzle in muzzleFlash)
                {
                    muzzle.light.enabled = false;
                }
            }

            // Turn off shoot animation state if shoot animation is complete
            if (!droneAnimator.GetCurrentAnimatorStateInfo(1).IsName("Shoot"))
            {
                droneAnimator.SetBool("Shooting", false);
            }

            if (CurrentShootInverval > ShootRate)
            {
                Debug.DrawLine(position, position + (direction * range), Color.red, 2.0f, false);
                CurrentShootInverval -= ShootRate;
                droneAnimator.SetBool("Shooting", true);

                // Shoot sound
                GameObject.Instantiate(droneFireSound, position, Quaternion.identity);

                // Start muzzle flash effect
                foreach (GameObject muzzle in muzzleFlash)
                {
                    muzzle.light.enabled = true;
                    muzzle.particleSystem.Play();
                    muzzleFlashInterval = 0.0f;
                }

                // Raycast in bullet direction
                RaycastHit hit;
                if (Physics.Raycast(position, direction, out hit, 100.0f, ignoreLayer))
                {
                    if (hit.collider.gameObject.tag == "PlayerOne")
                    {
                        HitFlash.FlashCamera(1);
                        if (PlayerOneHealth.DeductHP(Damage))
                        {
                            returnValue = true;
                        }
                    }
                    else if (hit.collider.gameObject.tag == "PlayerTwo")
                    {
                        HitFlash.FlashCamera(2);
                        if (PlayerTwoHealth.DeductHP(Damage))
                        {
                            returnValue = true;
                        }
                    }
                }
            }
            return(returnValue);
        }