Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            StartCoroutine(ShotEffect());

            Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
            RaycastHit hit;

            laserLine.SetPosition(0, barrelTip.position);

            if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
            {
                laserLine.SetPosition(1, hit.point);

                HitBox health = hit.collider.GetComponent <HitBox>();

                if (health != null)
                {
                    health.Damage(gunDamage);
                }
                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * hitForce);
                }
            }
            else
            {
                laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
            }
        }
    }
Пример #2
0
    void OnTriggerEnter(Collider other)
    {
        HitBox health = other.gameObject.GetComponent <HitBox>();

        if (health != null)
        {
            health.Damage(1);
        }
    }
Пример #3
0
    void OnTriggerEnter(Collider other)
    {
        HitBox health = other.gameObject.GetComponent <HitBox>();

        if (health != null && !hasHitPlayer)
        {
            health.Damage(1);
            if (health.simplehealth != null && health.simplehealth.Health < 1)
            {
                hasHitPlayer = true;
            }
            // Walk opposite dir
            ((EnemyBounceAndFallInput)characterInput).direction *= -1;
        }
    }
Пример #4
0
    void OnTriggerEnter(Collider other)
    {
        HitBox health = other.gameObject.GetComponent <HitBox>();

        if (health != null && !hasHitPlayer)
        {
            hasHitPlayer = true;
            health.Damage(1);
            if (other.transform.position.x > transform.position.x)
            {
                velocity = speed * -1;
            }
            else if (other.transform.position.x < transform.position.x)
            {
                velocity = speed;
            }
        }
    }