void Update() { if (player == null) { player = GameObject.FindGameObjectWithTag("Player"); } if (playerInventory == null && player != null) { playerInventory = player.GetComponent <ShootBehaviour>(); } // Handle player pick weapon action. if (this.pickable && Input.GetKeyDown(KeyCode.E)) { // Disable weapon physics. rbody.isKinematic = true; this.col.enabled = false; // Setup weapon and add in player inventory. playerInventory.AddWeapon(this); Destroy(interactiveRadius); this.Toggle(true); this.pickable = false; // Change active weapon HUD. TooglePickupHUD(false); } }
IEnumerator ExecuteAfterTime(float time) { yield return(new WaitForSeconds(time)); player = GameObject.FindGameObjectWithTag("Player"); // null because player isn't exist yet; playerInventory = player.GetComponent <ShootBehaviour>(); gameController = GameObject.FindGameObjectWithTag("GameController"); // Assert that exists a on-screen HUD. if (GameObject.Find("ScreenHUD") == null) { Debug.LogError("No ScreenHUD canvas found. Create ScreenHUD inside the GameController"); } weaponHud = GameObject.Find("ScreenHUD").GetComponent <WeaponUIManager>(); pickupHUD = gameController.transform.Find("PickupHUD"); // Create physics components and radius of interaction. col = this.transform.GetChild(0).gameObject.AddComponent <BoxCollider>(); CreateInteractiveRadius(col.center); this.rbody = this.gameObject.AddComponent <Rigidbody>(); // Assert that an weapon slot is set up. if (this.type == WeaponType.NONE) { Debug.LogWarning("Set correct weapon slot ( 1 - small/ 2- big)"); type = WeaponType.SHORT; } // Assert that the gun muzzle is exists. if (!this.transform.Find("muzzle")) { Debug.LogError(this.name + " muzzle is not present. Create a game object named 'muzzle' as a child of this game object"); } // Set default values. fullMag = mag; maxBullets = totalBullets; pickupHUD.gameObject.SetActive(false); }
public virtual void Initialize(WeaponData data) { weaponData = data; AmmoContainer = new AmmunitionContainer(weaponData.maxAmmoInMagazine, weaponData.startAmmunitionSize); shootBehaviour = new ShootBehaviour(muzzle, data.bulletData); }
public void Execute(GameObject obj) { ShootBehaviour script = obj.GetComponent <ShootBehaviour> (); if (script) { script.Shoot(); } }
public void Drop() { this.gameObject.SetActive(true); this.transform.position += Vector3.up; rbody.isKinematic = false; this.transform.parent = null; this.col.enabled = true; interactiveRadius.enabled = true; this.Pickable = true; playerShootBehavior = null; }
public void PickUpWeapon(ShootBehaviour shootBehaviour) { playerShootBehavior = shootBehaviour; rbody.isKinematic = true; this.col.enabled = false; playerShootBehavior.AddWeapon(this); interactiveRadius.enabled = false; this.Pickable = false; currentInventoryAmmoCount = playerShootBehavior.GetInventory().GetCurrentAmmo(weaponType) + mag; playerShootBehavior.GetInventory().AddAmmoToInventory(weaponType, mag); }
protected virtual void SetupTurretMappings() { SetCurrentForm(_forms[UpgradePointer].gameObject); _currentTurretMappping = _currentForm.GetComponent <TurretMapping>(); triggerSpt = _currentTurretMappping.GetComponentInChildren <TriggerSpt>(); turretHeadX = _currentTurretMappping.HeadX; turretHeadY = _currentTurretMappping.HeadY; shootBehaviour = _currentTurretMappping.shootBehavior; }
// Use this for initialization void Start() // Just reference setup. { player1 = GameObject.FindGameObjectWithTag("Player1"); player1Gun = player1.GetComponentInChildren <ShootBehaviour>(); player1StateManager = player1.GetComponent <PlayerStateManager>(); player1Inventory = player1.GetComponent <InventoryManager>(); player2 = GameObject.FindGameObjectWithTag("Player2"); if (player2 != null) { player2Gun = player2.GetComponentInChildren <ShootBehaviour>(); player2StateManager = player2.GetComponent <PlayerStateManager>(); player2Inventory = player2.GetComponent <InventoryManager>(); } }
private void Awake() { myTransform = transform; gameObject.name = this.label_weaponName; // 레이캐스트 무시 레이어 설정(하위 자식 모두) gameObject.layer = LayerMask.NameToLayer(FC.TagAndLayer.LayerName.IgnoreRayCast); foreach (Transform tr in this.myTransform) { tr.gameObject.layer = LayerMask.NameToLayer(FC.TagAndLayer.LayerName.IgnoreRayCast); } player = GameObject.FindGameObjectWithTag(FC.TagAndLayer.TagName.Player); playerInventory = player.GetComponent <ShootBehaviour>(); gameController = GameObject.FindGameObjectWithTag(FC.TagAndLayer.TagName.GameController); if (weaponHUD == null) { if (screenHUD == null) { screenHUD = GameObject.Find("ScreenHUD"); } weaponHUD = screenHUD.GetComponent <WeaponUIManager>(); } if (pickHUD == null) { pickHUD = gameController.transform.Find("PickupHUD"); } //Interactive 하기 위한 충돌체 설정 weaponCollider = myTransform.GetChild(0).gameObject.AddComponent <BoxCollider>(); CreateInteractiveRadius(weaponCollider.center); weaponRigidbody = gameObject.AddComponent <Rigidbody>(); if (this.weaponType == WeaponType.NONE) { this.weaponType = WeaponType.SHORT; } fullMag = currentMagCapacity; maxBullets = totalBullets; pickHUD.gameObject.SetActive(false); if (muzzleTransform == null) { muzzleTransform = transform.Find("muzzle"); } }
private void Awake() { thisTrans = transform; thisGameObject = gameObject; thisGameObject.name = label_WeaponName; thisGameObject.layer = LayerMask.NameToLayer(TagAndLayer.LayerName.IgnoreRayCast); for (int i = 0; i < transform.childCount; i++) { GameObject child = transform.GetChild(i).gameObject; child.layer = LayerMask.NameToLayer(TagAndLayer.LayerName.IgnoreRayCast); } player = GameObject.FindGameObjectWithTag(TagAndLayer.TagName.Player); playerInventory = player.GetComponent <ShootBehaviour>(); gameController = GameObject.FindGameObjectWithTag(TagAndLayer.TagName.GameController); if (weaponHUD == null) { if (screenHUD == null) { screenHUD = GameObject.Find("ScreenHUD"); } weaponHUD = screenHUD.GetComponent <WeaponUIManager>(); } if (pickHUD == null) { pickHUD = gameController.transform.Find("PickupHUD"); } weaponCollider = thisTrans.GetChild(0).gameObject.AddComponent <BoxCollider>(); CreateInteractiveRadius(weaponCollider.center); weaponRigidbody = thisGameObject.AddComponent <Rigidbody>(); if (weaponType == WeaponType.NONE) { weaponType = WeaponType.SHORT; } fullMag = currentMagCapacity; maxBullets = totalBullets; pickHUD.gameObject.SetActive(false); if (muzzleTrans == null) { muzzleTrans = thisTrans.Find("muzzle"); } }
bool moveWhileFacing; // Either move while facing player or stop movement and only face player void Awake() { player = GameObject.FindGameObjectWithTag("Player"); playerHP = player.GetComponent <PlayerHP>(); view = player.GetComponent <PlayerInView>(); movement = GetComponent <StoppableMovementBehaviour>(); anim = GetComponent <Animator>(); // Shoot behaviour must either be in main enemy object which this script is attached to or in child object shootBehaviourScript = GetComponentInChildren <ShootBehaviour>(); // Do not shoot until aggro'd if (shootBehaviourScript != null) { shootBehaviourScript.enabled = false; } }
private Transform pickupHUD; // Reference to the weapon pickup in-game label. void Awake() { // Set up the references. this.gameObject.name = this.label; this.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast"); foreach (Transform t in this.transform) { t.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast"); } player = GameObject.FindGameObjectWithTag("Player"); playerInventory = player.GetComponent <ShootBehaviour>(); gameController = GameObject.FindGameObjectWithTag("GameController"); // Assert that exists a on-screen HUD. if (GameObject.Find("ScreenHUD") == null) { Debug.LogError("No ScreenHUD canvas found. Create ScreenHUD inside the GameController"); } weaponHud = GameObject.Find("ScreenHUD").GetComponent <WeaponUIManager>(); pickupHUD = gameController.transform.Find("PickupHUD"); // Create physics components and radius of interaction. col = this.transform.GetChild(0).gameObject.AddComponent <BoxCollider>(); CreateInteractiveRadius(col.center); this.rbody = this.gameObject.AddComponent <Rigidbody>(); // Assert that an weapon slot is set up. if (this.type == WeaponType.NONE) { Debug.LogWarning("Set correct weapon slot ( 1 - small/ 2- big)"); type = WeaponType.SHORT; } // Assert that the gun muzzle is exists. if (!this.transform.Find("muzzle")) { Debug.LogError(this.name + " muzzle is not present. Create a game object named 'muzzle' as a child of this game object"); } // Set default values. fullMag = mag; maxBullets = totalBullets; pickupHUD.gameObject.SetActive(false); }
// Use this for initialization void Start() { // Initialise behaviour list m_behaviours = new List <IBehaviour>(); // Find the player game object player = FindObjectOfType <FPSController>().gameObject; playerScript = player.GetComponent <FPSController>(); currentHealth = maxHealth; //----------------------------------------------------------------- // The Flee Sequence // Set up the flee force and flee force parameter m_fleeForce = new HorizontalFleeForce(); m_fleeForce.SetTarget(player /*.transform.position + new Vector3 (2, 2, 2)*/); // Set up the flee behaviour fleeBehaviour = new SteeringBehaviour(); fleeBehaviour.Constructor(); fleeBehaviour.AddNewForce(m_fleeForce); // Set up condition for flee sequence WithinRange fleeCondition = new WithinRange(); fleeCondition.SetParameters(player, 1.5f); // Set up flee sequence Sequence fleeSequence = new Sequence(); fleeSequence.addBehaviour(fleeCondition); fleeSequence.addBehaviour(fleeBehaviour); //----------------------------------------------------------------- // The Attack Sequence // Set up the attack behaviour ShootBehaviour attackBehaviour = new ShootBehaviour(); attackBehaviour.SetTarget(player); attackBehaviour.SetWeaponType(ShootBehaviour.WeaponType.HitScanType); List <GameObject> guns = new List <GameObject>(); // Give a list of bullet spawners to the shoot behaviour foreach (Transform child in transform) { GunParticleSystem gun; gun = child.gameObject.GetComponent <GunParticleSystem>(); if (gun != null) { guns.Add(gun.gameObject); } } attackBehaviour.SetGuns(guns); // Set up condition for the attack sequence WithinRange attackCondition = new WithinRange(); attackCondition.SetParameters(player, attackRange); // Set up play sound behaviour PlaySound playAttackSound = new PlaySound(); if (stateAudioSource != null && attackStateClip != null) { playAttackSound.SetAudioSource(stateAudioSource); playAttackSound.SetAudioClip(attackStateClip); playAttackSound.SetTimer(15.0f); } // Set up attack sequence Sequence attackSequence = new Sequence(); attackSequence.addBehaviour(attackCondition); if (stateAudioSource != null && attackStateClip != null) { attackSequence.addBehaviour(playAttackSound); } attackSequence.addBehaviour(attackBehaviour); //----------------------------------------------------------------- // The Chase Sequence // Set up the seek force and seek force parameter m_seekForce = new SeekForce(); m_seekForce.SetTarget(player); // Set up the seek behaviour seekBehaviour = new SteeringBehaviour(); seekBehaviour.Constructor(); seekBehaviour.AddNewForce(m_seekForce); // Set up condition for chase sequence WithinRange chaseCondition = new WithinRange(); chaseCondition.SetParameters(player, chaseRange); // Set up play sound behaviour PlaySound playChaseSound = new PlaySound(); if (stateAudioSource != null && chaseStateClip != null) { playChaseSound.SetAudioSource(stateAudioSource); playChaseSound.SetAudioClip(chaseStateClip); playChaseSound.SetTimer(15.0f); } // Set up chase sequence Sequence chaseSequence = new Sequence(); chaseSequence.addBehaviour(chaseCondition); if (stateAudioSource != null && chaseStateClip != null) { chaseSequence.addBehaviour(playChaseSound); } chaseSequence.addBehaviour(seekBehaviour); //---------------------------------------------------------------- // The Patrol Sequence // Set up patrol behaviour PatrolBehaviour patrol = new PatrolBehaviour(); patrol.SetPatrolPoints(m_patrolPointA, m_patrolPointB); patrol.StartUp(); // Set up play sound behaviour PlaySound playPatrolSound = new PlaySound(); if (stateAudioSource != null && chaseStateClip != null) { playPatrolSound.SetAudioSource(stateAudioSource); playPatrolSound.SetAudioClip(patrolStateClip); playPatrolSound.SetTimer(15.0f); } // Set up patrol sequence Sequence patrolSequence = new Sequence(); if (stateAudioSource != null && chaseStateClip != null) { chaseSequence.addBehaviour(playPatrolSound); } patrolSequence.addBehaviour(patrol); //---------------------------------------------------------------- // The Main Selector // Set up main selector Selector mainSelector = new Selector(); mainSelector.addBehaviour(attackSequence); mainSelector.addBehaviour(chaseSequence); mainSelector.addBehaviour(patrolSequence); // Add all sequences to behaviour list m_behaviours.Add(mainSelector); // Setting the forward direction transform.forward = new Vector3(0, 0, 1); }
// Use this for initialization void Start() { sb = GetComponent <ShootBehaviour>(); cb = GetComponent <ChaseBehaviour>(); anim = GetComponentInChildren <Animator>(); }