Beispiel #1
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(this);
     }
 }
    private void Awake()
    {
        if (instance == null)
        {
            instance = this; //if theres no instance of the class, set it to this one
        }

        else if (instance != this)
        {
            Destroy(this); //prevents duplicates
        }
    }
Beispiel #3
0
    void Shoot()
    {
        //Debug.Log ("shooting");

        if (AmmunitionManager.getAmmoQuantity() < 1)
        {
            return;
        }


        Vector2 mousePos = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x,
                                       Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
        Vector2 firePointPos = new Vector2(firePoint.position.x,
                                           firePoint.position.y);

        Vector2 direction = mousePos - firePointPos;

        Debug.DrawLine(firePointPos, mousePos);

        RaycastHit2D hit = Physics2D.Raycast(firePointPos,
                                             direction,
                                             100,
                                             this.hitLayers);

        // Do the bullet stuff
        AmmunitionManager.spendAmmo(1);
        Effect();

        /*if (hit.collider != null)
         * {
         *      Debug.DrawLine (firePointPos, hit.point);
         *      Debug.Log ("Hit something! " + hit.transform.tag);
         *
         *      //hit.transform.GetComponent<Rigidbody2D>().velocity = new Vector2(4f, 2f);
         *      Rigidbody2D otherRigidBody = hit.transform.GetComponent<Rigidbody2D>();
         *
         *      otherRigidBody.velocity = new Vector2(2f, 0f);
         *      otherRigidBody.AddForceAtPosition(bulletForce, hit.point);
         * }*/
    }
    // -----------------------------------------------------------------
    // PRIVATE
    // -----------------------------------------------------------------

    private void Awake()
    {
        playerAmmo = GameObject.FindGameObjectWithTag("Player").GetComponent <AmmunitionManager>();
    }
    public static void AmmoItem(Transform target, float amount)
    {
        AmmunitionManager am = target.GetComponent <AmmunitionManager>();

        am.GetAmmo(amount);
    }