public virtual void Fire() { if (weaponScripts == null) { return; } if (weaponScripts.Count == 0) { return; } // find the weapon in the currently selected slot TEMPWeapon = (BaseWeaponScript)weaponScripts [selectedWeaponSlot]; theDir = transform.forward; if (useForceVectorDirection) { theDir = forceVector; } // fire the projectile TEMPWeapon.Fire(theDir, ownerNum); }
// Use this for initialization void Start() { selectedWeaponSlot = 0; lastSelectedWeaponSlot = -1; weaponSlots = new ArrayList(); weaponScripts = new ArrayList(); myTransfrom = transform; if (forceParent == null) { forceParent = myTransfrom; } TEMPvecto3 = forceParent.position; TEMProtation = forceParent.rotation; for (int i = 0; i < weapons.Length; i++) { TEMPgameObject = (GameObject)Instantiate(weapons[i], TEMPvecto3 + offSetWeaponSpwanPosition, TEMProtation); TEMPgameObject.transform.parent = forceParent; TEMPgameObject.layer = forceParent.gameObject.layer; TEMPgameObject.transform.position = forceParent.position; TEMPgameObject.transform.rotation = forceParent.rotation; weaponSlots.Add(TEMPgameObject); TEMPWeapon = TEMPgameObject.GetComponent <BaseWeaponScript>(); weaponScripts.Add(TEMPWeapon); TEMPgameObject.SetActive(false); } SetWeaponSlot(0); }
public void Start() { // default to the first weapon slot selectedWeaponSlot = 0; lastSelectedWeaponSlot = -1; // initialize weapon list ArrayList weaponSlots = new ArrayList(); // initialize weapon scripts ArrayList weaponScripts = new ArrayList(); // cache a reference to the transform (looking up a transform each step can be expensive, so this is important!) myTransform = transform; if (forceParent == null) { forceParent = myTransform; } // rather than look up the transform position and rotation of the player each iteration of the loop below, // we cache them first into temporary variables TEMPvector3 = forceParent.position; TEMProtation = forceParent.rotation; // we instantiate all of the weapons and hide them so that we can activate and use them // when needed. for (int i = 0; i < weapons.Length; i++) { // Instantiate the item from the weapons list TEMPgameObject = (GameObject)Instantiate(weapons[i], TEMPvector3 + offsetWeaponSpawnPosition, TEMProtation); // make this gameObject that our weapon controller script is attached to, to be the parent of the weapon // so that the weapon will move around with the player // // NOTE: if you need projectiles to be on a different layer from the main gameObject, set the layer of the // forceParent object to the layer you want projectiles to be on TEMPgameObject.transform.parent = forceParent; TEMPgameObject.layer = forceParent.gameObject.layer; TEMPgameObject.transform.position = forceParent.position; TEMPgameObject.transform.rotation = forceParent.rotation; // store a reference to the gameObject in an ArrayList weaponSlots.Add(TEMPgameObject); // grab a reference to the weapon script attached to the weapon and store the reference in an ArrayList TEMPWeapon = TEMPgameObject.GetComponent <BaseWeaponScript>(); weaponScripts.Add(TEMPWeapon); // disable the weapon TEMPgameObject.SetActive(false); } // now we set the default selected weapon to visible SetWeaponSlot(0); }
public void RandomWeapon() { if (curWeapon != null) { Destroy(curWeapon); } int rand = Random.Range(0, ChooseableWeapons.Length); curWeapon = Instantiate(ChooseableWeapons[2], transform.position, transform.rotation, transform); weapon = curWeapon.GetComponent <BaseWeaponScript>(); }
public void Start() { // Default to the firsst weapons slot SelectedWeaponSlot = 0; LastSelectedWeaponsSlot = -1; // Initialize weapon list Arraylist _weaponsSlots = new ArrayList(); // initialize weapon scripts ArrayList _weaponsScript = new ArrayList(); // Cache a reference to the transform (looking up a transform each step can be expensive // so this is importance) iTransform = transform; if (ForceParent == null) { ForceParent = iTransform; } // Rather than look up the transform position and rotation of the player each interatction of this loop below, // we cache them first into temporaty variables _tmpVector3 = ForceParent.position; _tmpProtation = ForceParent.rotation; // We instantiate all of the weapons and hide them so that we can active and use them when we needed. for (int i = 0; i < weapons.Length; i++) { // Instantiate the item from the weapon controller script is attched to, to be the parent of the weapon // so that the weapon will move around wwith the player // Note: If you need projectiles to be on a different player from the main gameObject, set the layer of the forceParent // objeect to the layer you want projecttiles to be on _tmpGameObject.transform.parent = ForceParent; _tmpGameObject.layer = ForceParent.gameObject.layer; _tmpGameObject.transform.position = ForceParent.position; _tmpGameObject.transform.rotation = ForceParent.rotation; // Store a reference to the gameObject in an ArrayList _weaponsSlots.Add(_tmpGameObject); // Grab a reference to the weapon script attached to the weapon and store the refence in an ArrayList _tmpWeapon = _tmpGameObject.GetComponent <BaseWeaponScript>(); _weaponsScript.Add(_tmpWeapon); // Disable the weapon _tmpGameObject.SetActive(false); } // Now we set the default selected weapon to visible SetWeaponSlot(0); }
public virtual void EnableCurrentWeapon() { if (weaponScripts.Count == 0) { return; } TEMPWeapon = (BaseWeaponScript)weaponScripts[selectedWeaponSlot]; TEMPWeapon.Enable(); TEMPgameObject = (GameObject)weaponSlots[selectedWeaponSlot]; TEMPgameObject.SetActive(true); }
void Update() { Move(); Wep = GameObject.FindWithTag("Weapon"); Weapon = Wep.GetComponent <BaseWeaponScript>(); Gamepad[] pads = Gamepad.all.ToArray(); if (pads.Length < 1) { Debug.LogError("Connect A Controller!!!"); return; } pDevicePad = pads[0]; if (pDevicePad.rightTrigger.wasPressedThisFrame) { Attack(); } if (pDevicePad.rightShoulder.wasPressedThisFrame) { Switch(); } if (pDevicePad.buttonNorth.wasPressedThisFrame) { if (isGrounded) { Jump(); } } if (pDevicePad.buttonEast.isPressed) { isRunning = true; Run(); } if (!pDevicePad.buttonEast.isPressed) { isRunning = false; if (!isRunning) { movementSpeed = 5.0f; } } if (pDevicePad.buttonWest.wasPressedThisFrame) { Reload(); } if (pDevicePad.buttonSouth.wasPressedThisFrame) { Interact(); } }
// Start is called before the first frame update void Start() { if (!(hasWeapon[0] || hasWeapon[1] || hasWeapon[2])) { currentWeapon = -1; } if (!weapons[(int)WeaponCodes.katana]) { weapons[(int)WeaponCodes.katana] = GameObject.FindGameObjectWithTag("PlayerKatana"); } if (!weapons[(int)WeaponCodes.revolver]) { weapons[(int)WeaponCodes.revolver] = GameObject.FindGameObjectWithTag("PlayerRevolver"); } if (!weapons[(int)WeaponCodes.shotgun]) { weapons[(int)WeaponCodes.shotgun] = GameObject.FindGameObjectWithTag("PlayerShotgun"); } previousWeapon = currentWeapon; int i = 0; foreach (GameObject weapon in weapons) { if (i == currentWeapon) { weapons[i].SetActive(true); currentWeaponScript = weapons[i].GetComponent <BaseWeaponScript>(); } else { weapons[i].SetActive(false); } i++; } if (currentWeaponScript) { currentWeaponScript.currentWeaponState = (int)WeaponState.idle; } AmmoText = GameObject.Find("AmmoText"); if (AmmoText && currentWeapon < 2) { AmmoText.SetActive(false); } }
// main Logic protected virtual void Init() { // default to the first weapon slot selectedWeaponSlot = 0; lastSelectedWeaponSlot = -1; // initialize weapon list ArrayList weaponSlots = new ArrayList(); // initialize weapon scripts ArrayList weaponScripts = new ArrayList(); // cache a reference to the transform myTransform = transform; if (forceParent == null) { forceParent = myTransform; } TEMPvector3 = forceParent.position; TEMProtation = forceParent.rotation; // we instantiate all of the weapons and hide them so that we can activate and use them when needed. for (int i = 0; i < weapons.Length; i++) { // Instantiate the item from the weapons list TEMPgameObject = (GameObject)Instantiate(weapons [i], TEMPvector3 + offsetWeaponSpawnPosition, TEMProtation); TEMPgameObject.transform.parent = forceParent; TEMPgameObject.layer = forceParent.gameObject.layer; TEMPgameObject.transform.position = forceParent.position; TEMPgameObject.transform.rotation = forceParent.rotation; // store a reference to the gameObject in an ArrayList weaponSlots.Add(TEMPgameObject); // grab a reference to the weapon script attached to the weapon and store the reference in an ArrayList TEMPWeapon = TEMPgameObject.GetComponent <BaseWeaponScript> (); weaponScripts.Add(TEMPWeapon); // disable the weapon TEMPgameObject.SetActive(false); } // now we set the default selected weapon to visible SetWeaponSlot(0); }
public virtual void EnableCurrentWeapon() { if (weaponScripts.Count == 0) { return; } // grab reference to currently selected weapon TEMPWeapon = (BaseWeaponScript)weaponScripts [selectedWeaponSlot]; // now tell the script to enable itself TEMPWeapon.Enable(); TEMPgameObject = (GameObject)weaponSlots [selectedWeaponSlot]; TEMPgameObject.SetActive(true); }
public virtual void DisableCurrentWeapon() { if (weaponScripts.Count == 0) { return; } // grab reference to currently selected weapon script TEMPWeapon = (BaseWeaponScript)weaponScripts [selectedWeaponSlot]; // now tell the script to disable itself TEMPWeapon.Disable(); // grab reference to the weapon's gameObject and disable that, too TEMPgameObject = (GameObject)weaponSlots [selectedWeaponSlot]; TEMPgameObject.SetActive(false); }
public virtual void EnableCurrentWeapon() { if (_weaponsScript.Count == 0) { return; } // Grab refrence to currently selected weapon _tmpWeapon = (BaseWeaponScript)_weaponsScript[SelectedWeaponSlot]; // Now tell the script to enable itselft _tmpWeapon.Enable(); _tmpGameObject = (GameObject)_weaponsSlots[SelectedWeaponSlot]; _tmpGameObject.SetActive(false); }
public virtual void Fire() { if (weaponScripts == null) { return; } if (weaponScripts.Count == 0) { return; } TEMPWeapon = (BaseWeaponScript)weaponScripts[selectedWeaponSlot]; theDir = myTransfrom.forward; if (useForceVectorDirection) { theDir = forceVector; } TEMPWeapon.Fire(theDir, ownerNum); }
public virtual void DisableCurrentWeapon() { if (_weaponsScript.Count == 0) { return; } // Grab reference to currently selected weapon script _tmpWeapon = (BaseWeaponScript)_weaponsScript[SelectedWeaponSlot]; // now tell the script to disable itself _tmpWeapon.Disable(); // Grab reference to the weapon's gameObject and disable the, too _tmpGameObject = (GameObject)_weaponsSlots[SelectedWeaponSlot]; _tmpGameObject.SetActive(false); }
public virtual void Fire() { if (_weaponsScript == null || _weaponsScript.Count == 0) { return; } // Find the weapon in the currently selected slot _tmpWeapon = (BaseWeaponScript)_weaponsScript[SelectedWeaponSlot]; TheDir = iTransform.forward; if (UseForceVectorDirection) { TheDir = ForceVector; } // fire the projectiles _tmpWeapon.Fire(TheDir, _ownerNum); }
void SwitchWeapons() { if (!hasWeapon[currentWeapon]) { return; } switchedWeapons = false; if (previousWeapon >= 0 && previousWeapon < weapons.Length) { weapons[previousWeapon].SetActive(false); } weapons[currentWeapon].SetActive(true); currentWeaponScript = weapons[currentWeapon].GetComponent <BaseWeaponScript>(); currentWeaponScript.currentWeaponState = (int)WeaponState.idle; if (currentWeapon == (int)WeaponCodes.katana) { AmmoText.SetActive(false); } }
void Update() { Wep = GameObject.FindWithTag("Weapon"); Weapon = Wep.GetComponent <BaseWeaponScript>(); Gamepad[] pads = Gamepad.all.ToArray(); if (pads.Length < 1) { Debug.LogError("Connect A Controller!!!"); return; } pDevicePad = pads[0]; if (pDevicePad.rightTrigger.wasPressedThisFrame) { Attack(); } if (pDevicePad.buttonWest.wasPressedThisFrame) { Reload(); } }