// Update is called once per frame void Update() { RaycastHit hit; if (Time.time > shootDelay + lastShoot) { if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); ZombieBehaviour zombie = hit.transform.GetComponent <ZombieBehaviour>(); if (zombie != null) { zombie.TakeDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(hit.normal * impactForce); } GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGO, 2f); } lastShoot = Time.time; SoundManagerScript.Instance.PlaySFX(SoundManagerScript.AudioClipID.SFX_SHOOT); } }
private void Attack() { int currentLoopNumber; if (!animator.GetCurrentAnimatorStateInfo(0).IsName("AttackMaya")) { return; } currentLoopNumber = (int)animator.GetCurrentAnimatorStateInfo(0).normalizedTime; if (currentLoopNumber > lastLoopNumber) { lastLoopNumber = currentLoopNumber; if (target.TakeDamage()) { target = null; } isAttacking = false; } }
void Shoot() { RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f); sphere.transform.position = hit.point; GameObject.Destroy(sphere.GetComponent <SphereCollider>()); Debug.Log(hit.transform.name); if (hit.transform.tag == "Zombie") { ZombieBehaviour Behaviour = hit.transform.gameObject.GetComponent <ZombieBehaviour>(); Debug.Log("Hit a zombie"); Behaviour.TakeDamage(damage); } } }