Esempio n. 1
0
    private void FixedUpdate()
    {
        if (!killed)
        {
            //MOVEMENT
            Vector2 velocity = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")) * SPEED;
            rb.velocity = velocity;
            //rb.MovePosition(rb.position + rb.velocity * Time.deltaTime);

            //FIRING
            if (Input.GetAxis("Horizontal") != 0)
            {
                lastLook = Mathf.Sign(Input.GetAxis("Horizontal"));
            }
            //Debug.Log("Axis=" + Input.GetAxis("Horizontal").ToString() + " Last look x=" + lastLook.ToString());
            if (Input.GetButtonDown("Fire1"))
            {
                GameObject  shot = Instantiate(projectile, bulletSpawnPoint.transform.position, Quaternion.identity);
                Rigidbody2D rb   = shot.GetComponent <Rigidbody2D>();
                rb.velocity = transform.right * projectile_speed * lastLook;
                SoldierAudio a = GetComponentInChildren <SoldierAudio>();
                a.PlayGunshot();
                //Debug.Log("velocity=" + rb.velocity);
            }
        }
    }
Esempio n. 2
0
    public void Kill()
    {
        alive = false;
        SoldierAudio a = GetComponentInChildren <SoldierAudio>();

        a.PlayDeath();
        //CHANGE SPRITE SET
        //SpriteRenderer s = GetComponent<SpriteRenderer>();
        //s.sprite = Resources.Load<Sprite>("Player/Injured/Playerinj_0001");
        Destroy(gameObject.GetComponent <Rigidbody2D>());
        Destroy(gameObject, decomposeTime);
    }
Esempio n. 3
0
 public void HandleHit()
 {
     //Player was shot, deal with it
     if (injured)
     {
         //end game
         checkPlayerDeath();
     }
     else
     {
         injured = true;
         SoldierAudio a = GetComponentInChildren <SoldierAudio>();
         a.PlayInjury();
     }
 }
Esempio n. 4
0
    private void checkPlayerDeath()
    {
        SoldierAudio a = GetComponentInChildren <SoldierAudio>();

        a.PlayDeath();
        --currentLives;
        //if player is out of lives, end the level
        if (currentLives == 0)
        {
            StartCoroutine(EndLevel(false));
        }
        else
        {
            //if the player has more lives, reset the player to the original location
            transform.position = startPosition;
            //rb.position = startPosition;
            injured = false;
        }
    }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        //MOVEMENT
        if (alive)
        {
            Move();
        }

        //FIRING
        if (alive && gunLoaded && CanTargetPlayer())
        {
            //shoot
            GameObject  shot = Instantiate(projectile, bulletSpawnPoint.transform.position, Quaternion.identity);
            Rigidbody2D rb   = shot.GetComponent <Rigidbody2D>();
            rb.velocity = transform.right * projectile_speed * lastLook;
            SoldierAudio a = GetComponentInChildren <SoldierAudio>();
            a.PlayGunshot();
            //Debug.Log("velocity=" + rb.velocity);
            gunLoaded = false;
            StartCoroutine(Reload());
        }
    }