コード例 #1
0
ファイル: AutoShoot.cs プロジェクト: waihoeh97/TPS
    // 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);
        }
    }
コード例 #2
0
    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;
        }
    }
コード例 #3
0
ファイル: gunControl.cs プロジェクト: costacoffeeboss/NEA
    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);
            }
        }
    }