Inheritance: MonoBehaviour
示例#1
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
 private void Start()
 {
     shootSource = GetComponent <AudioSource>();
     mainCam     = Camera.main;
     ammoCounter = FindObjectOfType <AmmoCounter>();
     ammoCounter.ChangeAmmoCount(Data.WeaponType, 0, false);
     OnEnable();
 }
示例#3
0
 public void Start()
 {
     if (instance != null)
     {
         Destroy(instance.gameObject);
     }
     instance = this;
 }
    void OnTriggerEnter2D(Collider2D Other)
    {
        if (Other.GetComponent <Rigidbody2D>() == null)
        {
            return;
        }
        AmmoCounter.AddAmmo(AddAmmo);

        Destroy(gameObject);
    }
示例#5
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.RightControl))
     {
         if (enabled)
         {
             Instantiate(Projectile, FirePoint.position, FirePoint.rotation);
             AmmoCounter.LoseAmmo();
         }
     }
 }
    void AddWeapon(BasicWeapon newWeapon, int weaponIndex)
    {
        GameObject  ammoCounterInstance = Instantiate(ammoCounterPrefab, ammosPanel);
        AmmoCounter newAmmoCounter      = ammoCounterInstance.GetComponent <AmmoCounter>();

        DebugUtility.HandleErrorIfNullGetComponent <AmmoCounter, WeaponHUDManager>(newAmmoCounter, this, ammoCounterInstance.gameObject);

        newAmmoCounter.Initialize(newWeapon, weaponIndex);

        m_AmmoCounters.Add(newAmmoCounter);
    }
    private void EquipWeapon(Weapon weapon, AmmoCounter ammoCounter)
    {
        leftHandWeapon = weapon;
        var leftHandParticleSystemChild = Instantiate(weapon.weaponPrefab, leftHandParticleSystemParent.transform);

        _leftHandBullets                = leftHandParticleSystemChild.GetComponent <ParticleSystem>();
        _leftHandSpriteSide             = weapon.spriteSide;
        _leftHandSpriteTop              = weapon.spriteTop;
        _leftHandWeaponInfo             = leftHandParticleSystemChild.GetComponent <WeaponInfo>();
        leftHandAmmoCounter             = ammoCounter;
        leftHandSpriteRendererUi.sprite = weapon.spriteUi;
        leftHandSpriteRendererUi.color  = new Color(1, 1, 1, 1);
        leftHandNameField.text          = weapon.name;
        leftHandAmmoField.text          = $"{leftHandAmmoCounter.currentAmmo}/{leftHandAmmoCounter.totalAmmo}";
        weaponAudioSource.clip          = weapon.audioClip;
        _isLeftHandFull = true;
    }
示例#8
0
    // Start is called before the first frame update
    void Start()
    {
        GameObject centerPoint = gameObject.transform.Find("HUDCenterPoint").gameObject;

        pivotOffset = gameObject.transform.position - centerPoint.transform.position;

        player = GameObject.FindGameObjectWithTag("Player");
        GameObject board = GameObject.FindGameObjectWithTag("ScoreBoard");

        scoreBoard = board.GetComponent <ScoreBoard>();
        GameObject bar = GameObject.FindGameObjectWithTag("HealthBar");

        healthBar = bar.GetComponent <HealthBar>();
        GameObject ammo = GameObject.FindGameObjectWithTag("AmmoCounter");

        ammoCounter = ammo.GetComponent <AmmoCounter>();
    }
示例#9
0
    // Use this for initialization
    void Start()
    {
        enemiesInRange = Physics2D.OverlapCircleAll(transform.position, 5);

        if (currentWeapon == null)
        {
            foreach (Transform child in transform)
            {
                if (child.gameObject.CompareTag("item"))
                {
                    currentWeapon = child;
                }
            }
            //currentWeapon =
        }
        ac = ammoCounter.GetComponent <AmmoCounter>();
        ac.newWeapon(currentWeapon.GetComponent <Weapon>());
        hpb         = hpbar.GetComponent <PlayerHPBar>();
        hpb.max     = health;
        hpb.current = hpb.max;
        hpb.setHP(health);
    }
示例#10
0
 private void Start()
 {
     myAmmoCounterScript = myAmmoCounter.GetComponent <AmmoCounter>();
 }
 private void Start()
 {
     animator    = GetComponent <Animator>();
     ammoCounter = FindObjectOfType <AmmoCounter>();
 }
示例#12
0
    private void HandleInteract(InputAction.CallbackContext context)
    {
        if (!isPaused && !isFrozen && !isDead)
        {
            //find closest interactable object
            GameObject[] interactables = GameObject.FindGameObjectsWithTag("Interactable");
            GameObject   closest       = interactables[0];
            var          minDistance   = Mathf.Infinity;
            foreach (GameObject interactable in interactables)
            {
                var thisDistance = (interactable.transform.position - transform.position).sqrMagnitude;
                if (thisDistance < minDistance)
                {
                    minDistance = thisDistance;
                    closest     = interactable;
                }
            }

            if (minDistance > interactRadiusSqr)
            {
                return;
            } //if object too far away

            //handle based on attached script
            var gir = closest.GetComponent <GroundItemRenderer>();
            if (gir) //dropped weapon
            {
                if (gir.weapon)
                {
                    if (!_isLeftHandFull)
                    {
                        EquipWeapon(gir.weapon, gir.ammoCounter);
                        Destroy(closest);
                    }
                    else
                    {
                        _weaponToSwap            = gir.weapon;
                        _weaponToSwapAmmoCounter = gir.ammoCounter;
                        _weaponToSwapGameObject  = closest;
                        gameStateController.swapWeaponPanel.SetActive(true);
                        gameStateController.PauseGame();
                    }
                }
                else if (gir.sword)
                {
                    if (!_isRightHandFull)
                    {
                        EquipSword(gir.sword);
                        Destroy(closest);
                    }
                    else
                    {
                        _swordToSwap           = gir.sword;
                        _swordToSwapGameObject = closest;
                        gameStateController.swapSwordPanel.SetActive(true);
                        gameStateController.PauseGame();
                    }
                }
            }
        }
    }
示例#13
0
 // Start is called before the first frame update
 void Start()
 {
     reloadText  = GetComponent <Text>();
     ammoCounter = FindObjectOfType <AmmoCounter>();
 }
示例#14
0
 // Use this for initialization
 void Start()
 {
     playerHealth = player.GetComponent <PlayerHealth> ();
     ammoCounter  = player.GetComponent <AmmoCounter>();
     cooldown     = player.GetComponent <Cooldown>();
 }
示例#15
0
 private void Start()
 {
     Canvas      = GameObject.FindGameObjectWithTag("Canvas");
     ammoCounter = Canvas.GetComponentInChildren <AmmoCounter>();
 }
示例#16
0
 private void Awake()
 {
     crosshair = GetComponentInChildren <DynamicCrosshair>();
     ammo      = GetComponentInChildren <AmmoCounter>();
 }
示例#17
0
 public override void Inititialize()
 {
     ammoCounter = WorldState.AmmoCounter;
 }
示例#18
0
 // Use this for initialization
 void Start()
 {
     playerHealth = player.GetComponent <PlayerHealth> ();
     ammoCounter = player.GetComponent <AmmoCounter>();
     cooldown = player.GetComponent <Cooldown>();
 }
示例#19
0
 void Start()
 {
     scoreBoard  = FindObjectOfType <ScoreBoard>();
     ammoCounter = FindObjectOfType <AmmoCounter>();
 }
示例#20
0
 public override void Inititialize()
 {
     ammoCounter   = WorldState.AmmoCounter;
     weaponChanger = WorldState.WeaponChanger;
 }