public Bullet Shoot(GameObject bulletPrefab, Vector2 direction)
    {
        if (m_playerLife && !m_playerLife.IsAlive())
        {
            return(null);
        }

        GameObject bullet       = (GameObject)Instantiate(bulletPrefab, (Vector2)m_transform.position + m_distanceOffset * direction, Quaternion.identity);
        Bullet     bulletScript = bullet.GetComponent <Bullet>();

        bulletScript.m_targetDirection = direction;
        if (BulletOverseer.Instance)
        {
            bullet.transform.SetParent(BulletOverseer.Instance.m_transform);
        }

        if (m_bulletSceneParent)
        {
            bullet.transform.parent = m_bulletSceneParent.transform;
        }

        if (m_playerAnimator)
        {
            m_playerAnimator.FireGun();
        }

        return(bulletScript);
    }
Esempio n. 2
0
    void Awake()
    {
        m_playerInput = GetComponent <PlayerInput>();
        m_playerLife  = GetComponent <LifeScript>();
        m_transform   = transform;
        m_rb2d        = GetComponent <Rigidbody2D>();

        m_alive = m_playerLife.IsAlive();
        m_playerLife.OnDeath += OnPlayerDeath;

        GameObject[] guns = { m_gunObjectUp, m_gunObjectRight, m_gunObjectDown };
        foreach (GameObject go in guns)
        {
            Animator gunAnim = go.GetComponent <Animator>();
            m_gunAnimators.Add(gunAnim);
            gunAnim.enabled = false;

            SpriteRenderer renderer = go.GetComponent <SpriteRenderer>();
            m_gunRenderers.Add(renderer);
            m_gunDefaultSprites.Add(renderer.sprite);
        }

        HideBodyObjects();
        HideGunObjects();
    }
    void FixedUpdate()
    {
        m_alive = !m_playerLife || m_playerLife.IsAlive();

        if (m_alive)
        {
            m_rigidbody2D.velocity += m_playerInput.m_movementInput * m_acceleration * Time.deltaTime;
            m_rigidbody2D.velocity -= m_rigidbody2D.velocity * m_friction * Time.deltaTime;
        }
    }
Esempio n. 4
0
 private bool CanSpawnEnemy()
 {
     return(!playerLife || playerLife.IsAlive());
 }