// Start is called before the first frame update
 public override void Start()
 {
     ActiveGun = findWeaponByID(activePrimary);
     ActiveGun.GetComponent <gun>().activate(true);
     base.Start();
     Player   = true;
     playerSc = GetComponentInParent <PlayerController>();
     firemode = ActiveGun.GetComponent <gun>().firemode;
     SwitchGrenade();
 }
Exemple #2
0
 /// <summary>
 /// Dispose of all the guns
 /// </summary>
 public void Dispose()
 {
     foreach (Gun g in collectedGuns)
     {
         g.Dispose();
     }
     if (ActiveGun != null)
     {
         ActiveGun.Dispose();
     }
 }
    private void OnTriggerEnter(Collider coll)
    {
        if (coll != null)
        {
            ActiveGun playerGun = coll.GetComponent <ActiveGun>();
            if (playerGun != null)
            {
                playerGun.pickup = pickup;

                if (!respawn)
                {
                    gameObject.SetActive(false);
                }
            }
        }
    }
 public void switchWeapon()
 {
     if (holdingPrimary)
     {
         ActiveGun.GetComponent <gun>().activate(false);
         ActiveGun = findWeaponByID(activeSecondary);
         ActiveGun.GetComponent <gun>().activate(true);
         firemode       = ActiveGun.GetComponent <gun>().firemode;
         holdingPrimary = false;
     }
     else
     {
         ActiveGun.GetComponent <gun>().activate(false);
         ActiveGun = findWeaponByID(activePrimary);
         ActiveGun.GetComponent <gun>().activate(true);
         firemode       = ActiveGun.GetComponent <gun>().firemode;
         holdingPrimary = true;
     }
 }
    // Use this for initialization
    void Start()
    {
        if (isServer)
        {
            //Telling the GameManager who the players are
            for (int i = 0; i < GameManager.instance.GO_Player.Length; i++)
            {
                //For the current index, if it's empty
                if (GameManager.instance.GO_Player[i] == null)
                {
                    //Make the gameobject this, and quit the cycle of sadness
                    GameManager.instance.GO_Player[i] = gameObject;
                    Debug.Log("Player added");
                    break;
                }
            }
        }

        //If the camera is local player
        if (isLocalPlayer)
        {
            //From the camera follow script, set the reference to this game object.
            CameraFollow.PlayerRef = gameObject;
        }
        else if (!isLocalPlayer)
        {
            return;
        }

        activeGun       = GetComponent <ActiveGun>();
        amPunch         = GetComponent <AMPunch>();
        RB_PC           = GetComponent <Rigidbody>();
        FL_defaultSpeed = FL_moveSpeed;

        //When the player exists in the scene, the player will stop the theme and start playing the game BGM.
        AudioManager.instance.Stop("Theme");
        AudioManager.instance.Play("Game BGM");
    }
    private void Update()
    {
        if (playerSc.isAlive)
        {
            line.transform.position = ActiveGun.GetComponent <gun>().tip.position;
            if (Input.GetButtonDown("Switch"))
            {
                switchWeapon();
            }
            if (Input.GetButtonDown("Reload"))
            {
                ActiveGun.GetComponent <gun>().reload();
            }
            if (Input.GetButton("Grenade"))
            {
                if (GrenadeHoldTime < grenadeMaxHoldTime)
                {
                    GrenadeHoldTime += Time.deltaTime;
                }
            }
            if (Input.GetButtonUp("Grenade"))
            {
                Transform tip = ActiveGun.GetComponent <gun>().tip.transform;
                if (grenadeCount[ActiveGrenade % 300] > 0)
                {
                    Grenades G = Instantiate(findWeaponByID(ActiveGrenade), tip.position, tip.rotation).GetComponent <Grenades>();
                    G.GrenadeAimTime = GrenadeHoldTime / grenadeMaxHoldTime;
                    GrenadeHoldTime  = 0;
                    grenadeCount[ActiveGrenade % 300]--;
                }
                if (grenadeCount[ActiveGrenade % 300] < 1)
                {
                    SwitchGrenade();
                }
            }
            switch (firemode)
            {
            case 1:
                if (Input.GetButton("Fire1"))
                {
                    shoot();
                    playerSc.isShooting = true;
                }
                else
                {
                    playerSc.isShooting = false;
                }
                break;

            case 2:
                if (Input.GetButtonDown("Fire1"))
                {
                    shoot();
                    playerSc.isShooting = true;
                }
                else
                {
                    playerSc.isShooting = false;
                }
                break;
            }
            if (Input.GetButtonDown("SwitchGrenade"))
            {
                SwitchGrenade();
            }
        }
    }