// Kill all zombies in a wave and destroy it public void DestroyWave(int wave_id) { var list = GetWaveListByID(wave_id); // Return if the wave does not exist if (list == null) { return; } // Else kill all zombies in the wave // First obtain the zombies helth scripts List <ZombieHealth> zombieHealths = new List <ZombieHealth>(); foreach (GameObject zomb in list) { ZombieHealth zhl = zomb.GetComponent <ZombieHealth>(); zombieHealths.Add(zhl); } // Then kill all the zombies foreach (var zhl in zombieHealths) { zhl.Damage(zhl.health * 2); } // Then remove the whole KVP from the kvp array zombies_wawes.Remove(new KeyValuePair <int, List <GameObject> >(wave_id, list)); }
void Shoot() { Vector2 BulletSpawnPosition = new Vector2(bulletSpawn.position.x, bulletSpawn.position.y); if (PlayerController.lastPressed == "a") { hit = Physics2D.Raycast(BulletSpawnPosition, new Vector2(-1, 0), 100, whatToHit); } else if (PlayerController.lastPressed == "w") { hit = Physics2D.Raycast(BulletSpawnPosition, new Vector2(0, 1), 100, whatToHit); } else if (PlayerController.lastPressed == "d") { hit = Physics2D.Raycast(BulletSpawnPosition, new Vector2(1, 0), 100, whatToHit); } else if (PlayerController.lastPressed == "s") { hit = Physics2D.Raycast(BulletSpawnPosition, new Vector2(0, -1), 100, whatToHit); } if (hit.collider != null) { Debug.Log("hit something"); enemy = hit.collider.GetComponent <ZombieHealth>(); if (enemy != null) { Debug.Log("hit zombie1"); StartCoroutine("WaitForBulletTouchZombie"); } } }
// void ShootRay() { if (Physics.Raycast(shootMark.position, shootMark.forward, out hit, weaponRange, layer)) { if (hit.transform.tag == "Enemy") { ZombieHealth zombiehealth = hit.transform.GetComponent <ZombieHealth>(); zombiehealth.HealthAmount(damageZombie); Instantiate(bloodfromEnemy, hit.point, transform.rotation); //Debug.Log("Hit Enemy"); //Debug.DrawLine(shootMark.position, hit.point); //Debug.Log(hit.transform.tag); } else if (hit.transform.tag == "HeadofZombie") { Debug.Log("headshoot"); ZombieHealth zombiehealth = hit.transform.GetComponentInParent <ZombieHealth>(); zombiehealth.HealthAmount(headshootDamage); gunshootv1.PlayOneShot(headshootvoice); Instantiate(bloodfromEnemy, hit.point, transform.rotation); hit.transform.gameObject.SetActive(false); } else { //Debug.Log("Hit something else"); Debug.Log(hit.transform.name); //Debug.DrawLine(shootMark.position, hit.point); // Debug.Log(hit.transform.tag); } } }
void Start() { Zombie = transform.parent; _state = Zombie.GetComponent <ZombieSM>(); curAnim = Zombie.GetComponent <tk2dSpriteAnimator>(); zombieHealth = Zombie.GetComponent <ZombieHealth>(); }
private void Shoot() { Ray ray = _camera.ScreenPointToRay(target); RaycastHit hit = new RaycastHit(); //camera shake EventBroadcaster.Instance.PostEvent(EventNames.FinalGameEvents.ON_GUN_SHOT_SHAKE); EventBroadcaster.Instance.PostEvent(EventNames.FinalGameEvents.ON_CURSOR_SHOT); gunShotAudio.Play(); if (Physics.Raycast(ray, out hit, Range, _shootableMask)) { //print("hit " + hit.collider.gameObject); onHitParticle.Stop(); Vector3 onHitPosition = hit.point; onHitParticle.transform.position = onHitPosition; onHitParticle.Play(); ZombieHealth health = hit.collider.GetComponent <ZombieHealth>(); if (health != null) { health.TakeDamage(1); } } }
// Use this for initialization void Awake() { player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent <PlayerHealth>(); zombieHealth = GetComponent <ZombieHealth>(); animator = GetComponent <Animator>(); }
/** * Make the player shoot on left click. */ void Shoot() { timer = 0f; // Reset timer. // Enable gun effects. gunLight.enabled = true; //gunParticles.Stop(); // If particles are still playing, stop them //gunParticles.Play(); // and start them again. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set line at position of barrel. gunSound.Play(); ray.origin = transform.position; ray.direction = transform.forward; if (Physics.Raycast(ray, out hit, range, shootable)) //('out hit' provides information of what was hit with raycast) { /* Take away zombie's health. */ ZombieHealth health = hit.collider.GetComponent <ZombieHealth>(); // Get zombie health script. if (health != null) // Make sure we hit a Zombie and not something like the vehicles. { // Make Zombie take damage: health.TakeDamage(damage, hit.point); } gunLine.SetPosition(1, hit.point); // Set line end point to what we shot. } else // Just draw a line if not shooting at something that is 'shootable'. { gunLine.SetPosition(1, ray.origin + ray.direction * range); } }
public void FireStreaming() { //CurrentWeapon = WeaponSelection.ActiveWeaponNumber; //var power = "weapon" + (CurrentWeapon + 1) + "speed"; //CurrentWeaponSpeed = PlayerPrefs.GetFloat(power); //Debug.Log("CurrentWeaponSpeed " + CurrentWeaponSpeed); nextTimeToFire = (Time.time + 1f / fireRate); RaycastHit hit; if (Physics.Raycast(partToRotate.position, partToRotate.forward, out hit, range)) { particalStream.Play(); anim.SetBool("Fire", true); ZombieHealth zombieHealth = hit.collider.GetComponent <ZombieHealth>(); if (zombieHealth != null) { zombieHealth.DamageTaken(Damage); } } else { particalStream.Stop(); anim.SetBool("Fire", false); } }
void Shoot(PhotonPlayer attacker, Vector3 shootPosition) { if (!PhotonNetwork.isMasterClient) //如果玩家不是MasterClient,结束函数的执行 { return; } Vector3 rotatedPos = transform.rotation * shootingPosition; //随着角色的旋转,射击的初始位置也需要跟着旋转 ray.origin = rotatedPos + transform.position; //设置射击射线的起始端点 ray.direction = gunTransform.forward; //设置射击射线的方向 var hitTag = ""; //击中物体的Tag if (lineRenderer != null && lineObj == null) { GameObject go = Instantiate(lineRenderer, Vector3.zero, Quaternion.identity) as GameObject; lineObj = go.GetComponent <LineRenderer>(); } Vector3 bulletEffectPosition; //子弹爆炸效果的位置 //发出射击射线,判断是否击中物体 if (Physics.Raycast(ray, out hitInfo, shootingRange)) //如果射线击中游戏对象 { GameObject go = hitInfo.collider.gameObject; //获取被击中的游戏对象 if (go.tag == "Player") //如果击中玩家 { PlayerHealth playerHealth = go.GetComponent <PlayerHealth>(); if (playerHealth.team != GetComponent <PlayerHealth> ().team) //如果被击中玩家队伍与攻击者玩家队伍不同 { playerHealth.TakeDamage(shootingDamage, attacker); //被击中玩家扣血 } } else if (go.tag == "Zombie" || go.tag == "Guard" || go.tag == "Skeleton") //如果击中僵尸 { ZombieHealth zh = go.GetComponent <ZombieHealth> (); if (zh != null) { zh.TakeDamage(shootingDamage, shootPosition, attacker); //僵尸扣血 } } hitTag = go.tag; bulletEffectPosition = hitInfo.point; //击中游戏对象,子弹爆炸效果的位置在击中点 } else { bulletEffectPosition = ray.origin + shootingRange * ray.direction; //如果未击中,子弹爆炸效果为子弹失效的位置 } if (lineObj != null) { lineObj.SetWidth(0.02F, 0.02F); lineObj.SetPosition(0, ray.origin); lineObj.SetPosition(1, bulletEffectPosition); } photonView.RPC("ShootEffect", PhotonTargets.AllViaServer, bulletEffectPosition, hitTag); //使用RPC,调用所有玩家对象的ShootEffect函数,显示射击效果 }
void Awake() { // Set up the references. player = GameObject.FindGameObjectWithTag("Player").transform; playerHealth = player.GetComponent <PlayerHealth>(); enemyHealth = GetComponent <ZombieHealth>(); nav = GetComponent <UnityEngine.AI.NavMeshAgent>(); }
void Start() { zombieAnimator = GetComponent <Animator>(); zombieRigidBody = GetComponent <Rigidbody2D>(); zombieHealth = GetComponent <ZombieHealth>(); zombieMovement = GetComponent <ZombieMovement>(); zombieIK2D = GetComponent <UnityEngine.U2D.IK.IKManager2D>(); }
float timer; // Timer for counting up to the next attack. void Awake() { // Setting up the references. player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent <PlayerHealth>(); zombieHealth = GetComponent <ZombieHealth>(); anim = GetComponent <Animator>(); }
void Start() { zombie = GetComponent <Zombie>(); zombieHealth = GetComponent <ZombieHealth>(); zombieMovement = GetComponent <ZombieMovement>(); player = FindObjectOfType <Player>(); playerPosition = GetComponent <PlayerPosition>(); }
Animator anim; // Reference to the animator void Awake() { // Set up the references. player = GameObject.FindGameObjectWithTag("Player").transform; playerHealth = player.GetComponent <PlayerHealth>(); zombieHealth = GetComponent <ZombieHealth>(); nav = GetComponent <NavMeshAgent>(); anim = GetComponent <Animator>(); }
void Start() { zombie = GetComponent <Zombie>(); zombieHealth = GetComponent <ZombieHealth>(); zombieRigidBody = GetComponent <Rigidbody2D>(); zombieAttack = GetComponent <ZombieAttack>(); playerPosition = GetComponent <PlayerPosition>(); RandomJump(); }
//射击函数 void Shoot() { AudioSource.PlayClipAtPoint(shootingAudio, transform.position); //播放射击音效 //枪口闪光特效 if (GunShootingEffect != null && shootingEffectTransform != null) { (Instantiate(GunShootingEffect, shootingEffectTransform.position, shootingEffectTransform.rotation) as GameObject).transform.parent = shootingEffectTransform; } ray.origin = myCamera.transform.position; //设置射线发射的原点:摄像机所在的位置 ray.direction = myCamera.transform.forward; //设置射线发射的方向:摄像机的正方向 if (gunLine != null) { gunLine.enabled = true; //进行射击时,启用线渲染器(激光射线效果) gunLine.SetPosition(0, transform.position); //设置线渲染器(激光射线效果)第一个端点的位置:玩家枪械的枪口位置 } //发射射线,射线有效长度为shootingRange,若射线击中任何游戏对象,则返回true,否则返回false if (Physics.Raycast(ray, out hitInfo, shootingRange)) { if (hitInfo.transform.gameObject.tag.Equals("Enemy")) //当被击中的游戏对象标签为Enemy,表明射线击中敌人 //获取敌人生命值组件 { ZombieHealth enemyHealth = hitInfo.transform.gameObject.GetComponent <ZombieHealth> (); if (enemyHealth != null) { //调用EnemyHealth脚本的TakeDamage()函数,对敌人造成shootingDamage的伤害,注意,这里需要传入攻击者所在的位置 enemyHealth.TakeDamage(shootingDamage, myCamera.transform.position); } } if (gunLine != null) { gunLine.SetPosition(1, hitInfo.point); //当射线击中游戏对象时,设置线渲染器(激光射线效果)第二个端点的位置:击中对象的位置 gunLine.SetWidth(LINE_RENDERER_START, //射线在射程内击中对象时,需要根据击中对象的位置动态调整线渲染器(激光射线效果)的宽度 Mathf.Clamp((hitInfo.point - ray.origin).magnitude / shootingRange, LINE_RENDERER_START, LINE_RENDERER_END)); } if (bulletEffect != null) { Instantiate(bulletEffect, hitInfo.point, Quaternion.identity); } } else { if (bulletEffect != null) { Instantiate(bulletEffect, ray.origin + ray.direction * shootingRange, Quaternion.identity); } } // if (gunLine != null) { // //当射线未击中游戏对象时,设置线渲染器(激光射线效果)第二个端点的位置:射线射出后的极限位置 // gunLine.SetPosition (1, ray.origin + ray.direction * shootingRange); // //射线在射程内未击中对象,直接设置射线的初始与末尾宽度 // gunLine.SetWidth (LINE_RENDERER_START, LINE_RENDERER_END); // } }
void Awake() { // To-Do faire une boucle pour tous les player crée zombieAudio = GetComponent <AudioSource>(); player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent <PlayerHealth>(); enemyHealth = GetComponent <ZombieHealth>(); anim = gameObject.GetComponent <Animator>(); }
private void SpawnEnemy(float healthIncrease = 0) { int spawnerID = Random.Range(0, spawners.Length); GameObject healthIncrement = Instantiate(enemy, spawners[spawnerID].transform.position, spawners[spawnerID].transform.rotation); ZombieHealth ZombieScript = healthIncrement.GetComponent <ZombieHealth>(); ZombieScript.maxHealth += healthIncrease; ZombieScript.curHealth = ZombieScript.maxHealth; }
void Awake() { player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent <PlayerHealth> (); zombieAudio = GetComponent <AudioSource> (); zombieHealth = GetComponent <ZombieHealth>(); anim = GetComponent <Animator> (); GameObject feedbackObject = GameObject.FindGameObjectWithTag("Feedback"); feedback = feedbackObject.GetComponent <Text>(); }
private ZombieHealth zombieHealth; // Zombie health script reference void Awake() { //Debug.Log("Find Player Tag"); player = GameObject.FindGameObjectWithTag("Player"); // Locate the Player playerHealth = player.GetComponent <PlayerHealth> (); // Get the health script component of the Player zomAudio = GetComponent <AudioSource> (); zombieHealth = GetComponent <ZombieHealth>(); // Get component script Zombie health anim = GetComponent <Animator> (); // Reference to animator component scream = false; }
private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Enemy") { ZombieHealth zombieHealth = other.GetComponent <ZombieHealth>(); if (zombieHealth != null) { zombieHealth.DamageTaken(damage); Destroy(gameObject); return; } } }
void OnTriggerStay(Collider other) { if (other.tag == "Player" && canAttack) { ZombieHealth myHealth = gameObject.transform.parent.GetComponent <ZombieHealth>(); if (!myHealth.isStunned && !myHealth.isDead) { other.GetComponent <Player>().curHealth -= attackDamage; canAttack = false; StartCoroutine(BiteCooldown()); } } }
void Awake() { players = GameObject.FindGameObjectsWithTag("Player"); zombieHealth = GetComponent <ZombieHealth>(); nav = GetComponent <NavMeshAgent>(); audioSource = GetComponent <AudioSource>(); animator = GetComponentInChildren <Animator>(); animator.SetFloat("Speed", 1f); timer = (float)0.8 * timeBetweenSounds; }
public void Fire() { RaycastHit hit; // Check if the weapon fired hit something if (currentWeapon.Fire(out hit)) { ZombieHealth zombieHealth = hit.collider.GetComponent <ZombieHealth>(); if (zombieHealth != null) { zombieHealth.TakeDamage(currentWeapon.damage, hit, player); } } }
// Use this for initialization void Start() { anim = GetComponent <Animator>(); maxSpeed = 20f; radiusOfSat = 1.5f; range = 20f; turnSpeed = 5f; targetPoint = Vector3.zero; endpoint = trans.position; player = GameObject.FindGameObjectWithTag("Player"); playerTrans = GameObject.FindGameObjectWithTag("Player").transform; playerRb = GameObject.FindGameObjectWithTag("Player").GetComponent <Rigidbody>(); health = GetComponent <ZombieHealth>(); audio = GetComponent <AudioSource>(); }
//启动时调用 void Start() { //获取僵尸的各种组件 agent = GetComponent <NavMeshAgent>(); animator = GetComponent <Animator>(); zombieHealth = GetComponent <ZombieHealth> (); zombieSensor = GetComponentInChildren <ZombieSensor> (); zombieRender = GetComponent <ZombieRender> (); zombieTransform = transform; //把僵尸感知到的玩家字段设置为null targetPlayer = null; EnableZombie(false); AIInitFinish = true; }
private Transform targetPlayer; //僵尸感知范围内的玩家 //初始化 void OnEnable() { zombieTransform = transform; //获取Transform组件 animator = GetComponent <Animator>(); //获取动画管理器组件 agent = GetComponent <NavMeshAgent>(); //获取NavMeshAgent组件 //agent.updateRotation = false; //agent.updatePosition = false; zombieHealth = GetComponent <ZombieHealth> (); //获取僵尸生命值管理组件 zombieSoundSensor = GetComponentInChildren <ZombieSoundSensor> (); //获取僵尸感知器组件 zombieRender = GetComponent <ZombieRender>(); //获取僵尸渲染器控制组件 targetPlayer = null; //僵尸初始化时,未发现玩家,该值设为null curState = FSMState.Wander; //初始化僵尸状态 }
//启动时调用 void Start() { //获取guard的各种组件 agent = GetComponent <NavMeshAgent>(); animator = GetComponent <Animator>(); guardHealth = GetComponent <ZombieHealth> (); guardSensor = GetComponentInChildren <GuardSensor> (); guardTransform = transform; //把guard感知到的玩家字段设置为null targetPlayer = null; //获取guard感知范围 var ob = GameObject.Find("GuardSenseArea"); guardActiveRange = ob.GetComponent <MeshFilter>().mesh.bounds.size.x *ob.transform.localScale.x; }
private void checkForZombie() { GameObject[] zombieObjects = GameObject.FindGameObjectsWithTag("Zombie"); zombies = new Zombie[zombieObjects.Length]; for (int i = 0; i != zombieObjects.Length; i++) { zombies[i] = zombieObjects[i].GetComponent <Zombie>(); if (checkRange(zombies[i].transform.position, transform.position, zombies[i].width / 2, zombies[i].height / 2)) { Debug.Log("Hit it"); zombieHealth = zombieObjects[i].GetComponent <ZombieHealth>(); zombieHealth.DamageEnemy(gameAttribute.weaponPower); GameMaster.KillBullet(this); } } }
void CmdTellServerWhichZombieWasShow(string uniqueID, int dmg) { // ゾンビIDでGameObjectを取得 GameObject go = GameObject.Find(uniqueID); if (GameManagerRefarences.NullCheck(go, "zombieID" + uniqueID)) { return; } // ダメージを与える ZombieHealth zombieHealth = go.GetComponent <ZombieHealth>(); if (GameManagerRefarences.NullCheck(zombieHealth, "ZombieHealth")) { return; } zombieHealth.DeductHealth(dmg); }
// Use this for initialization void Start() { zombieHealthScript = transform.parent.GetComponent<ZombieHealth>(); }
void Start() { Zombie = transform.parent; _state = Zombie.GetComponent<ZombieSM>(); curAnim = Zombie.GetComponent<tk2dSpriteAnimator>(); zombieHealth = Zombie.GetComponent<ZombieHealth>(); }
void Awake() { GameObject[] playersInGame = GameObject.FindGameObjectsWithTag("Player"); player = playersInGame[Random.Range(0, playersInGame.Length)]; playerHealth = player.GetComponent <PlayerHealth> (); zombieAudio = GetComponent <AudioSource> (); zombieHealth = GetComponent<ZombieHealth>(); anim = GetComponent <Animator> (); GameObject feedbackObject = GameObject.FindGameObjectWithTag("Feedback"); feedback = feedbackObject.GetComponent<Text>(); }