Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;

            StartCoroutine(ShotEffect());

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

            laserLine.SetPosition(0, gunEnd.position);

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

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

                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));
            }
        }
    }
Beispiel #2
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "Collideable")
        {
            Destroy(gameObject);
            // play sparky anim :D
        }



        if (col.gameObject.tag == "Enemy") // TODO: Change `Enemy` to `ShootableObject` because sometimes we may want to shoot world-objects (chest? breakable door?) for a reaction, so we'll need to share the name of this layer
        {
            gameObject.GetComponent <Projectile>().StopBullet();

            ShootableObject target = col.gameObject.GetComponent <ShootableObject>(); // ShootableObject will be the base class for anything that is hittable, create a Dragon? It extends `ShootableObject`.
            target.UpdateHealth(-1.0f * m_damage);
            if (target.m_current_health <= 0.0f)
            {
                StartCoroutine(HeadExplode());
            }
            else
            {
                StartCoroutine(BloodSplatter());
            }
        }
    }
Beispiel #3
0
    public void Start()
    {
        m_target        = GetComponentInParent <ShootableObject>();
        m_health_text   = GetComponentInChildren <Text>();
        m_max_bar_width = m_inner_health_bar.rect.width;
        m_max_health    = m_target.GetMaxHealth();

        SetHealthTextDisplayByPercent(1.0f);
    }
Beispiel #4
0
 public void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.layer == Constants.SHOOTEABLE_MASK)
     {
         ShootableObject shootableObject = other.collider.GetComponent <ShootableObject>();
         if (shootableObject != null)
         {
             shootableObject.TakeDamage(attributes.DamagePerShot);
         }
     }
     Destroy(gameObject);
 }