コード例 #1
0
ファイル: GunController.cs プロジェクト: AMTerp/UnityProjects
    // Use this for initialization
    void Start()
    {
        attachedToPlayer = transform.parent.parent.name.Equals("Main Camera");

        gunSounds     = GetComponent <AudioSource>();
        animations    = transform.GetChild(0).GetComponent <Animation>();
        ammoUI        = GameObject.FindWithTag("Ammo UI").GetComponent <AmmoUIController>();
        bulletTimerUI = GameObject.FindWithTag("Bullet Timer").GetComponent <BulletTimer>();

        idlePosition = transform.GetChild(0).localPosition;
        idleRotation = transform.GetChild(0).localEulerAngles;
        idleScale    = transform.GetChild(0).localScale;

        // Get the length of the animation clip for gunfire.
        // This code only works if the default clip in the Animation component is the gunshot animation.
        shotAnimationLength = animations.clip.length;

        currAmmoInClip = magazineSize;
        currSpareAmmo  = initSpareAmmo;
        canFire        = true;
        zoomedIn       = false;
        nextFire       = 0.0f;

        if (attachedToPlayer)
        {
            mainCamera = transform.parent.parent.GetComponent <Camera>();
            initFOV    = mainCamera.fieldOfView;
        }
        else
        {
            // Add a slight random extra delay to each turret such that they don't all shoot the same target.
            firePause *= (aiDelay + Random.Range(0.0f, 0.01f));
        }
    }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        mainCamera     = transform.Find("Main Camera").gameObject;
        ammoUI         = GameObject.FindWithTag("Ammo UI").GetComponent <AmmoUIController>();
        gameController = GameObject.FindWithTag("GameController").GetComponent <GameController>();
        bulletTimerUI  = GameObject.FindWithTag("Bullet Timer").GetComponent <BulletTimer>();

        currWeaponSlotHeld = 1;
        gunController      = mainCamera.transform.Find("Weapon Slot " + currWeaponSlotHeld).GetChild(0).GetComponent <GunController>();

        ammoUI.setAmmoCount(gunController.currAmmoInClip, gunController.currSpareAmmo);
    }
コード例 #3
0
ファイル: BuyAmmoButton.cs プロジェクト: AMTerp/UnityProjects
    // Use this for initialization
    void Start()
    {
        button          = gameObject.GetComponent <Button>();
        buttonText      = transform.GetChild(0).gameObject.GetComponent <Text>();
        ammoUI          = GameObject.FindWithTag("Ammo UI").GetComponent <AmmoUIController>();
        shopAudioSource = shopAudioGameObject.GetComponent <AudioSource>();
        moneyController = GameObject.FindWithTag("Money UI").GetComponent <MoneyController>();
        gameController  = GameObject.FindWithTag("GameController").GetComponent <GameController>();

        buttonText.text = string.Format("1x {0} Magazine ({1})", gunName, ammoCost);

        button.onClick.AddListener(buyAmmo);
    }