void Start () { weaponhandler = GameObject.FindGameObjectWithTag ("WeaponHandler").GetComponent<WeaponHandler> (); int tempx = x; int tempy = y; int slotAmount = 0; if (GameObject.FindGameObjectWithTag ("ItemDatabase")) { dataBase = GameObject.FindGameObjectWithTag ("ItemDatabase").GetComponent<ItemDatabase> (); } else { Debug.Log("Hmm does not look you have the ItemDatabse object on your player. can you add that for me?"); } for (int i = 0; i <Collums; i++) { for (int k = 0; k<Rows; k++){ GameObject slot = (GameObject)Instantiate(slots); slot.GetComponent<SlotScript>().slotNumber = slotAmount; Items.Add(new Item()); slotAmount++; Slots.Add(slot); slot.transform.SetParent (this.gameObject.transform); slot.GetComponent<RectTransform>().localScale = new Vector3(1,1,1); slot.name = "slot" +i +"," +k; slot.GetComponent<RectTransform>().localPosition = new Vector3(tempx,tempy,0); tempx = tempx + spacing; if (k == Rows -1){ tempx = x; tempy = tempy -spacing; } } } }
// Use this for initialization void Start () { weaponhandler = GameObject.FindGameObjectWithTag ("WeaponHandler").GetComponent<WeaponHandler> (); itemAmount = gameObject.transform.GetChild (1).GetComponent<Text> (); inventory = GameObject.FindGameObjectWithTag ("Inventory").GetComponent<Inventory>(); itemImage = gameObject.transform.GetChild (0).GetComponent<Image> (); showinv = GameObject.FindGameObjectWithTag ("Player").GetComponent<ShowInventory> (); }
// Use this for initialization void Start () { weaponhandler = GameObject.FindGameObjectWithTag ("WeaponHandler").GetComponent<WeaponHandler> (); itemAmount = gameObject.transform.GetChild (1).GetComponent<Text> (); inventory = GameObject.FindGameObjectWithTag ("Inventory").GetComponent<Inventory>(); itemImage = gameObject.transform.GetChild (0).GetComponent<Image> (); buildingManager = GameObject.FindGameObjectWithTag("Player").GetComponentInChildren<BuildingManager>(); stats = GameObject.FindGameObjectWithTag ("Player").GetComponent<PlayerStats> (); }
// Start is called before the first frame update void Start() { BasicMovement[] ListMovements = FindObjectsOfType <BasicMovement>(); mSlider = GetComponent <Slider>(); foreach (BasicMovement bm in ListMovements) { if (bm.IsCurrentPlayer) { plWH = bm.gameObject.GetComponentInChildren <WeaponHandler>(); return; } } }
//Set the owner of this weapon,对象需要WeaponHandler脚本 public void SetOwner(WeaponHandler wp) { owner = wp; if (owner == null) { DisableEnableComponents(true); StartCoroutine(CanBePickUp()); } else { DisableEnableComponents(false); } }
public void EquipOnWeapon(WeaponHandler weaponForEquiping) { if (weaponForEquiping == null || weaponForEquiping.SilencerHandler != null) { GameObject.SetActive(true); return; } SpawnSilencer(GameObjectForPlayer, weaponForEquiping.GameObjectForPlayer); SpawnSilencer(_silencerForWorldWeapon, weaponForEquiping.GameObject); weaponForEquiping.SilencerHandler = this; weaponForEquiping.CurrentShotSound = weaponForEquiping.Weapon_SO.shotSoundWithSilencer; }
public void Drop() { //playerHolding.handler.movement.sensitivityModifier.Add(sensitivityWhileAiming, this); //playerHolding.handler.movement.movementSpeed.Add(speedWhileAiming, this); playerHolding = null; weaponVisualTransform.localPosition = Vector3.zero; weaponVisualTransform.localRotation = Quaternion.identity; transform.SetParent(null); GetComponent <Collider>().enabled = true; GetComponent <Rigidbody>().isKinematic = false; enabled = false; }
void Pickup(GameObject weapon) { // Load weapon stats WeaponHandler weaponStats = weapon.GetComponent <WeaponHandler>(); InventoryManager.CreateItem(weaponStats.weapon.inventoryID); // Attach new weapon to player weapon.transform.parent = transform; weapon.transform.position = transform.position; // Update player stats based on current weapon attackHandler.SetModifiers(weaponStats); }
// as property -- to not sync by .networking //public GadgetHandler public void Inflate(PlayerAvatar avatar, Data data) // TODO variable? { var weaponPrefab = Resources.Load <WeaponHandler> ("Prefabs/Equipment/Weapons/" + WeaponName); var weapon = data.GetWeaponByName(WeaponName); WeaponHandler = MonoBehaviour.Instantiate <WeaponHandler>(weaponPrefab, avatar.weaponTransformContainer); //WeaponHandler.transform.SetParent(weaponTransformContainer, false); WeaponHandler.Init(weapon, avatar.player); InflateAnim(avatar); }
public override void Awake() { movement = GetComponent <PlayerController>(); weapons = GetComponent <WeaponHandler>(); ammo = GetComponent <AmmunitionInventory>(); stateHandler = GetComponent <GameStateHandler>(); audio = GetComponent <AudioSource>(); hud.player = this; base.Awake(); }
public void SwitchWeapons(Animator animator) { if (Time.time >= switchTime + switchCooldown) { index++; index %= weapons.Count; currentWeapon.gameObject.SetActive(false); currentWeapon = weapons[index]; currentWeapon.gameObject.SetActive(true); switchTime = Time.time; animator.runtimeAnimatorController = currentWeapon.GetAnimator(); return; } return; }
// Start is called before the first frame update void Start() { playerController = gameObject.GetComponent <PlayerController>(); isThrowing = false; player = GameObject.Find("Test_Player"); boomerang = GameObject.Find("Boomerang"); //boomerangHolder = GameObject.Find("BoomerangTest(Clone)"); weaponHandler = gameObject.GetComponent <WeaponHandler>(); //boomerang.GetComponent<MeshRenderer>().enabled = false; //boomerangRotate = gameObject.transform.GetChild(0); locationInFrontOfPlayer = new Vector3(player.transform.position.x, player.transform.position.y, player.transform.position.z) + player.transform.forward * 10f; //StartCoroutine(BoomerangThrow()); }
/* * Vector3 position; * Vector3 rotation; * private void LateUpdate() * { * * } */ #endregion public void PickUp(PlayerHandler ph) { playerHolding = ph.weapons; playerHolding.handler.movement.sensitivityModifier.Add(sensitivityWhileAiming, this); playerHolding.handler.movement.movementSpeed.Add(speedWhileAiming, this); transform.SetParent(playerHolding.defaultHoldingPosition); transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; GetComponent <Collider>().enabled = false; GetComponent <Rigidbody>().isKinematic = true; enabled = true; playerHolding.GetHeldWeapons(); }
private void OnTriggerEnter2D(Collider2D collision) { // TODO: avoid enemes picking up powerUps WeaponHandler weaponHandler = collision.GetComponent <WeaponHandler>(); if (weaponHandler == null) { // collided with a object withot a weaponHandler } else { // collided with a object with a weaponHandler weaponHandler.ChangeWeapon(weapon); Destroy(gameObject); SoundManager.PlaySound("powerUp"); } }
private void Shoot(WeaponHandler activeWeapon) { if (activeWeapon.weaponFireType == WeaponFireType.MULTIPLE) { if (Input.GetKey(Keycode.MOUSE_LEFTCLICK) && Time.time > nextTimeToFire) { nextTimeToFire = Time.time + 1f / fireRate; activeWeapon.ShootAnimation(); FireBullet(); } } else { if (Input.GetKeyDown(Keycode.MOUSE_LEFTCLICK)) { if (activeWeapon.tag == Tags.AXE) { activeWeapon.ShootAnimation(); } else if (activeWeapon.weaponBulletType == WeaponBulletType.BULLET) { activeWeapon.ShootAnimation(); FireBullet(); } else { if (isAiming) { activeWeapon.ShootAnimation(); if (activeWeapon.weaponBulletType == WeaponBulletType.ARROW) { // Shoot Arrow ShootArrow(); } else if (activeWeapon.weaponBulletType == WeaponBulletType.SPEAR) { // Throw Spear ThrowSpear(); } } } } } }
private void WeaponShoot(WeaponHandler weaponHandler) { if (!Input.GetMouseButtonDown(0)) { return; } switch (weaponHandler.weaponFireType) { case WeaponFireType.SINGLE: SingleShoot(weaponHandler); break; case WeaponFireType.MULTIPLE: BulletShoot (weaponHandler); break; } }
public void OnSwitchWeapon() { if (secondWeapon == null) { return; } activeWeapon.Show(false); WeaponHandler temp = activeWeapon; activeWeapon = secondWeapon; secondWeapon = temp; activeWeapon.Show(true); SetAnimatorController(activeWeapon.weapon.animatorController); armsAnim.SetTrigger("Switch"); activeWeapon.Unholster(); PlayerUI.SetAmmoText(activeWeapon); }
private void Zoom(WeaponHandler weaponHandler) { if (weaponHandler.weaponAim == WeaponAim.NONE) { return; } switch (weaponHandler.weaponAim) { case WeaponAim.AIM: ZoomGun(); break; case WeaponAim.SELF_AIM: AimWeapon(weaponHandler); break; case WeaponAim.NONE: return; } }
protected void SetUpCustomScript() { bool findObj = false; foreach (Transform child in this.transform) { foreach (Transform grandChild in child) { nowWeapon = grandChild.gameObject.GetComponent <WeaponHandler>(); if (nowWeapon != null) { findObj = true; break; } } if (findObj == true) { break; } } }
void Death() { // Set the death flag so this function won't be called again isDead = true; // Turn off the movement and shooting scripts playerMove.enabled = false; //stopping the player for moving player.GetComponent <PlayerRotation> ().enabled = false; //stopping the player from rotating WeaponHandler weaponStop = player.GetComponent <WeaponHandler>(); //getting the weapon handler if (weaponStop.theWeapon is ProjectileWeapon) { player.GetComponentInChildren <Gun> ().enabled = false; } else if (weaponStop.theWeapon is MeleeWeapon) { player.GetComponentInChildren <Melee> ().enabled = false; } player.GetComponent <Arsenal>().enabled = false; //stopping the weapon swapping }
private void BulletShoot(WeaponHandler weaponHandler) { if (Input.GetMouseButtonDown(0) && Time.time > nextTimeToFire) { weaponHandler.playSoundShoot(); weaponHandler.muzzleFlashTurnOn(); weaponHandler.ShootAnimation(); if (weaponHandler.isBulletPrefabExist()) { Instantiate(weaponHandler.bulletPrefab, weaponHandler.startPosition.transform.position, weaponHandler.startPosition.transform.rotation); } else { if (Physics.Raycast(mainCamera.transform.position, mainCamera.transform.forward, out RaycastHit hit)) { Debug.DrawRay(mainCamera.transform.position, transform.TransformDirection(mainCamera.transform.forward * 1000), Color.yellow); print("We Hit" + hit.transform.gameObject.name); } } } }
public void RecoilHandler(float recoilApplyRate, WeaponHandler playerHolding) { if (recoilToApply > 0) { float r = recoilToApply * recoilApplyRate * Time.deltaTime; Vector2 rd = new Vector2(Random.Range(-1f, 1f), 1); if (rd.magnitude > 1) { rd.Normalize(); } playerHolding.handler.movement.LookAngle(r * rd); // Add recoil recoilToApply -= r; } else if (!Input.GetButton("Fire")) // Return recoil using recoil recovery float { //print("Recovering from recoil"); } // Figure out how to have visual gun recoil // 1: Use lerping and an animation curve to move gun between standard and fully recoiled position // 2: Just give it a spring joint and use Physics.AddForce or AddForceAtPosition to make it jump back }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.GetComponent <WeaponHandler>() != null) { WeaponHandler weapon = collision.GetComponent <WeaponHandler>(); if (weapon.IsThrown) { return; } if (weapon.parentObject == this.gameObject) { return; } EntityStatHandler statHandler = GetComponent <EntityStatHandler>(); EntityStatHandler eStatHandler = collision.GetComponent <WeaponHandler>().parentObject.GetComponent <EntityStatHandler>(); lastHitBy = collision.GetComponent <WeaponHandler>().parentObject; switch (weapon.ScaledStat) { case statType.strength: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Str, eStatHandler.Level); break; case statType.dexterity: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Dex, eStatHandler.Level); break; case statType.inteligence: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Intl, eStatHandler.Level); break; case statType.defense: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Def, eStatHandler.Level); break; } GetComponent <EntityAnimation>().isHurt = true; } }
}//Check throw void PickUpObject(GameObject weapon) { carriedHandler = weapon.GetComponent <WeaponHandler>(); weapon.transform.GetChild(1).GetComponent <Collider>().enabled = false; switch (carriedHandler.weaponType) { case WeaponType.TWO_HANDED: rightHandWeapon = weapon; leftHandWeapon = weapon; weapon.transform.parent = rightHand; attackScript.rightDamage = attackScript.leftDamage = carriedHandler.damage; weapon.transform.localPosition = carriedHandler.holdPosition; weapon.transform.localEulerAngles = carriedHandler.holdRotation; weapon.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezePosition; ChangeLayerRecursively(weapon.transform, Layers.FPS); break; case WeaponType.ONE_HANDED: if (rightHandWeapon == null) { weapon.transform.parent = rightHand; rightHandWeapon = weapon; attackScript.rightDamage = carriedHandler.damage; } else { weapon.transform.parent = leftHand; leftHandWeapon = weapon; attackScript.leftDamage = carriedHandler.damage; } weapon.transform.localPosition = carriedHandler.holdPosition; weapon.transform.localEulerAngles = carriedHandler.holdRotation; weapon.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezePosition; ChangeLayerRecursively(weapon.transform, Layers.FPS); break; } }//Pickup Object
public override void OnPickup(Collider collider) { base.OnPickup(collider); WeaponHandler wph = collider.GetComponent <WeaponHandler>(); Weapon wp = gameObject.GetComponent <Weapon>(); if (wph && wp) { if (wph.weaponList.Contains(wp)) { return; } //否则 //防止再次触发拾取 gameObject.GetComponent <SphereCollider>().enabled = false; wph.AddWeaponToList(wp); if (wph.currentWeapon == null) { wph.currentWeapon = wp; } } }
private void ZoomInAndOut(WeaponHandler activeWeapon) { if (activeWeapon.weaponAim == WeaponAim.AIM) { // Zoom In if (Input.GetKeyDown(Keycode.MOUSE_RIGHTCLICK)) { FPCameraAnimator.Play(AnimatorTags.ZOOM_IN); crosshair.SetActive(false); } // Zoom Out if (Input.GetKeyUp(Keycode.MOUSE_RIGHTCLICK)) { FPCameraAnimator.Play(AnimatorTags.ZOOM_OUT); crosshair.SetActive(true); } } if (activeWeapon.weaponAim == WeaponAim.SELF_AIM) { // Aim if (Input.GetKeyDown(Keycode.MOUSE_RIGHTCLICK)) { activeWeapon.Aim(true); isAiming = true; } // Un Aim if (Input.GetKeyUp(Keycode.MOUSE_RIGHTCLICK)) { activeWeapon.Aim(false); isAiming = false; } } }
void Start () { weaponhandler = GameObject.FindGameObjectWithTag ("WeaponHandler").GetComponent<WeaponHandler> (); }
/// <summary> /// Initializes a new instance of the <see cref="Elf" /> class. /// </summary> /// <param name="weaponHandler">The weapon handler.</param> /// <param name="qualities">The qualities.</param> public Elf(WeaponHandler weaponHandler, SkillsContainer qualities) { this.weaponHandler = weaponHandler; this.qualities = qualities; }
private void Awake() { inputData = GameContext.Instance.InputData; isShootingEnabled = true; weaponHandler = new WeaponHandler(); }
// Use this for initialization public void init(GameObject plr) { player = plr; playerHandler = player.GetComponentInChildren <WeaponHandler>(); }
// Use this for initialization void Start() { characterMove = GetComponent <CharacterMovement>(); weaponHandler = GetComponent <WeaponHandler>(); SetupCrosshairs(); }
/// <summary> /// Initializes a new instance of the <see cref="Samurai" /> class. /// </summary> /// <param name="weaponHandler">The weapon handler.</param> /// <param name="theQualities">The qualities.</param> public Samurai(WeaponHandler weaponHandler, SkillsContainer theQualities) { this.weaponHandler = weaponHandler; this.qualities = theQualities; }
// Use this for initialization void Start() { characterMove = GetComponent <CharacterMovement>(); mainCam = Camera.main; weaponHandler = GetComponent <WeaponHandler>(); }
protected virtual void Start() { weaponHandler = GetComponent<WeaponHandler>(); animator = GetComponent<Animator>(); }
// Use this for initialization void Start () { inventory = GameObject.FindGameObjectWithTag ("Inventory").GetComponent<Inventory> (); weaponhandler = GameObject.FindGameObjectWithTag ("WeaponHandler").GetComponent<WeaponHandler> ();; }
void Start(){ wh = GameObject.FindGameObjectWithTag ("WeaponHandler").GetComponent<WeaponHandler> (); hf = GameObject.FindGameObjectWithTag ("MainCamera").GetComponent<HeadFollow> (); ml = GameObject.FindGameObjectWithTag ("MainCamera").GetComponent<SmoothMouseLook> (); }
/// <summary> /// Initializes a new instance of the <see cref="AncientGreek" /> class. /// </summary> /// <param name="weaponHandler">The weapon handler.</param> /// <param name="qualities">The qualities.</param> public AncientGreek(WeaponHandler weaponHandler, SkillsContainer qualities) { this.weaponHandler = weaponHandler; this.qualities = qualities; }
// Start is called before the first frame update void Start() { weaponHandler = GetComponent <WeaponHandler>(); shipMovement = GetComponent <PlayerShipMovement>(); }
//Sets weapon owner public void SetOwner(WeaponHandler wpHandler) { owner = wpHandler; }
public void Start() { Instance = this; }
//Sets the owner of this weapon public void SetOwner(WeaponHandler wp) { owner = wp; }
void Start() { anim = GetComponent<Animator>(); anim.SetLayerWeight(1, 1.0f); anim.SetLayerWeight(2, 1.0f); timeScript = GetComponent<TimeActions>(); camScript = GetComponent<ThirdPersonCamera>(); activationHandler = GetComponent<ActivationHandler>(); weapHandler = GetComponent<WeaponHandler>(); ammoScript = GetComponent<Ammo>(); playerActivationHandler = GetComponent<PlayerActivationHandler>(); cloneActivationHandler = GetComponent<CloneActivationHandler>(); flash = GameObject.Find("Flash").GetComponent<Screenflash>(); if(anim.layerCount == 2) anim.SetLayerWeight(1, 1); mMoving = false; anim.SetBool("GetUp", getUpAtStart); }