Exemplo n.º 1
0
    public void MakeGun(int level, int rarity)
    {
        //print ("this activated");
        gunLevel  = level;
        gunRarity = rarity;

        //get my component and gun
        GunBuilder myGunBuilder = GetComponent <GunBuilder> ();

        GunBuilder.Gun myGun = myGunBuilder.myGun;

        //gun builder will handle randomising
        myGun.gunLevel  = gunLevel;
        myGun.gunRarity = gunRarity;
        myGunBuilder.RandomizeGunParts();
        myGunBuilder.SetGunParts();

        //randomly pick level and part

        /*myGun.bodyType = giveRandomLevelPart(body);
        *  myGun.barrelType = giveRandomLevelPart(barrel);
        *  myGun.scopeType = giveRandomLevelPart(scope);
        *  myGun.stockType = giveRandomLevelPart(stock);
        *  myGun.gripType = giveRandomLevelPart(grip);*/

        //enable colliders
        myGunBuilder.shouldCollide = true;

        //create gun
        myGunBuilder.enabled = true;
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //shoot a ray when key e pressed
        if (Input.GetKeyDown(KeyCode.E))
        {
            Ray        r = new Ray(myCam.transform.position, myCam.transform.forward);
            RaycastHit hit;
            if (Physics.Raycast(r, out hit))
            {
                GunBuilder myGunBuilder = hit.collider.gameObject.GetComponentInParent <GunBuilder>();                //get the gun builder

                if (!myGunBuilder)
                {
                    return;
                }

                float distance = Vector3.Distance(myCam.transform.position, myGunBuilder.transform.position);
                //if it exists and close enough
                if (distance < pickGunDistance)
                {
                    GunBuilder myRealGunBuilder = GunController.myGunCont.gameObject.GetComponent <GunBuilder>();                    //get our gun builder


                    GunBuilder.Gun temp = myRealGunBuilder.myGun;
                    myRealGunBuilder.myGun = myGunBuilder.myGun;
                    myGunBuilder.myGun     = temp;


                    myRealGunBuilder.BuildGun();
                    myGunBuilder.BuildGun();
                    myGunBuilder.PickEffect();
                    anim.SetTrigger("isPicked");

                    //delete pickup
                    //Destroy(myGunBuilder.gameObject);
                }
            }
        }
    }