public void EquipWeapon(ScriptableWeapon weaponToEquip) { UnequipWeapon(); currentWeapon = weaponToEquip; SpawnWeapon(); }
private void Start() { ScriptableWeapon temp = gc.availableWeapons.FirstOrDefault(x => x.weaponName == "Basic Gun"); Debug.Log(temp.name); weaponSystem = new WeaponSystem(temp); }
public void Equip(ScriptableItem itemToEquip) { // Instantiate graphic equippedItemGameObject = GameObject.Instantiate(itemToEquip.graphic); // Attach to parent bone equippedItemGameObject.transform.SetParent(m_boneReference); // Apply local position, rotation and scale equippedItemGameObject.transform.localPosition = itemToEquip.instantiatedPosition; equippedItemGameObject.transform.localEulerAngles = new Vector3( itemToEquip.instantiatedRotation.x, itemToEquip.instantiatedRotation.y, itemToEquip.instantiatedRotation.z ); equippedItemGameObject.transform.localScale = itemToEquip.instantiatedScale; equippedItem = itemToEquip; // @ If equipment is a weapon, update Weapon_ID parameter ScriptableWeapon weapon = (ScriptableWeapon)equippedItem; if (weapon != null && weapon.weaponType != null) { m_owner.GetComponent <Animator>().SetInteger(Constants.WEAPON_ID, (int)weapon.weaponType); } }
// Helpers void EquipUnarmed() { UnequipWeapon(); currentWeapon = unarmedWeapon; SpawnWeapon(); }
private void OnTriggerEnter(Collider collider) { Weapon w; if (w = collider.GetComponent <Weapon>()) { //Get Entity if (w.transform.root.GetComponent <Entity>().faction == faction) { return; } ScriptableWeapon weaponData = (ScriptableWeapon)w.data; TakeDamage(this, weaponData.damage); am.SetTrigger("hit"); Instantiate(bloodSplash, collider.transform.position, Quaternion.identity); target = collider.transform.root; w.GetComponent <Collider>().enabled = false; DamageIndicatorItem i = Instantiate(indItem, transform.Find("DamageIndicator")).GetComponent <DamageIndicatorItem>(); i.damage = (int)weaponData.damage; i.c = Color.red; i.speed = Random.Range(1f, 2f); if (!GetComponent <AudioSource>().isPlaying) { GetComponent <AudioSource>().PlayOneShot(grunts[Random.Range(0, grunts.Count - 1)]); } } }
public void EnableCollider() { Weapon p = ts.GetItem("Weapon_R").GetChild(0).GetComponent <Weapon>(); p.GetComponentInChildren <Collider>().enabled = true; ScriptableWeapon weaponData = (ScriptableWeapon)p.GetComponent <Weapon>().data; p.GetComponent <AudioSource>().PlayOneShot(weaponData.actionsSound[Random.Range(0, weaponData.actionsSound.Count - 1)]); }
// @Constructor public Weapon(GameObject owner, ScriptableWeapon scriptableWeapon, GameObject weaponGameObject) { this.m_owner = owner; this.m_scriptableWeapon = scriptableWeapon; this.m_weaponGameObject = weaponGameObject; // @ Assign needed components audioSource = this.m_weaponGameObject.GetComponent <AudioSource>(); inventory = this.m_owner.GetComponent <InventoryManager>().inventory; animator = this.m_owner.GetComponent <Animator>(); }
public void SheatPrimary() { Transform weapon = ts.GetItem("Weapon_R").GetChild(0); weapon.SetParent(ts.GetItem("Sabre")); weapon.localPosition = Vector3.zero; weapon.localRotation = Quaternion.identity; ScriptableWeapon weaponData = (ScriptableWeapon)weapon.GetComponent <Weapon>().data; weapon.GetComponent <AudioSource>().PlayOneShot(weaponData.sheatSound); e.state = e.defaultState; }
private void OnCollisionEnter(Collision collision) { Debug.Log(collision.collider.transform.name); Tool t; if (t = collision.collider.GetComponent <Tool>()) { ScriptableWeapon w = (ScriptableWeapon)t.data; TakeDamage(GetComponent <Entity>(), w.damage); collision.collider.GetComponent <Collider>().enabled = false; } }
public void DrawPrimary() { Transform weapon = ts.GetItem("Sabre").GetChild(0); weapon.SetParent(ts.GetItem("Weapon_R")); weapon.localPosition = Vector3.zero; weapon.localRotation = Quaternion.Euler(97, -145, 50); ScriptableWeapon weaponData = (ScriptableWeapon)weapon.GetComponent <Weapon>().data; weapon.GetComponent <AudioSource>().PlayOneShot(weaponData.drawSound); e.state = EntityState.Aggressive; }
public void UnequipWeapon() { // Remove listeners if (hitbox != null) { hitbox.OnHit.RemoveListener(HitTarget); } // Destroy old weapon gameobject instance if (weaponGameObject != null) { Destroy(weaponGameObject); } // Cleanup references hitbox = null; weaponGameObject = null; currentWeapon = null; }
public void Unequip() { // @ If equipment to unequip is a weapon, update Weapon_ID parameter ScriptableWeapon weapon = (ScriptableWeapon)equippedItem; if (weapon != null) { // We should guarantee that both hands dont have a weapon equipped before doing this: // If we unequip a pistol and have a pistol on the other hand, we will run into issues. Animator animator = m_owner.GetComponent <Animator>(); if (!animator.GetBool(Constants.IS_DUAL_WIELDING)) { animator.SetInteger(Constants.WEAPON_ID, 0); } } equippedItem = null; GameObject.Destroy(equippedItemGameObject); }
private void OnTriggerEnter(Collider other) { Item i; if ((i = other.GetComponent <Item> ()) != null && i.isOnGround && selectedItem == null) { selectedItem = i.gameObject; i.DisplayItemInfos(); return; } Weapon w; if ((w = other.GetComponent <Weapon>()) != null && !w.isOnGround && w.transform.root != transform) { ScriptableWeapon weaponData = (ScriptableWeapon)w.data; w.GetComponent <Collider>().enabled = false; TakeDamage(this, weaponData.damage); if (!GetComponent <AudioSource>().isPlaying) { GetComponent <AudioSource>().PlayOneShot(grunts[Random.Range(0, grunts.Count - 1)]); } DamageIndicatorItem ind = Instantiate(indItem, transform.Find("DamageIndicator")).GetComponent <DamageIndicatorItem>(); ind.damage = (int)weaponData.damage; ind.c = Color.red; ind.speed = Random.Range(1f, 2f); am.SetTrigger("hit"); } }
void Awake() { unarmedWeapon = Resources.Load <ScriptableWeapon>(UNARMED_WEAPON_PATH); }
public WeaponSystem(ScriptableWeapon weapon) { currentWeapon = weapon; ReloadTimer = currentWeapon.reloadSpeed; Magazine = currentWeapon.magazineCapacity; }
public void SetWeaponData(ScriptableWeapon weaponData) { _weaponData = weaponData; }
private void WeaponHasChanged(ScriptableWeapon weaponData) { _weapon.SetWeaponData(weaponData); }