Ejemplo n.º 1
0
    protected override void UseShooting()
    {
        RaycastHit hit;

        if (Physics.Raycast(new Ray(this.cameraTransform.position, this.cameraTransform.TransformDirection(Vector3.forward)), out hit, this.distance))
        {
            if (hit.transform.root == this.cameraTransform.root)
            {
                return;
            }
            Rigidbody rigidbody = hit.transform.GetComponent <Rigidbody>();
            if (rigidbody != null)
            {
                rigidbody.AddForce((hit.point - this.cameraTransform.position).normalized * this.force);
            }
            Terminatable terminatable = hit.transform.GetComponent <Terminatable>();
            if (terminatable != null)
            {
                terminatable.Hit(this.damage, hit, this.cameraTransform.root);
            }
            else
            {
                Destroyable destroyable = hit.transform.GetComponent <Destroyable>();
                if (destroyable != null)
                {
                    destroyable.Explode(hit.point);
                }
            }
        }
    }
Ejemplo n.º 2
0
 public void Hit(float damage, RaycastHit hit, Transform attacker)
 {
     if (this.onHit != null)
     {
         this.onHit.Invoke(attacker);
     }
     if (blood && hit.point != Vector3.zero)
     {
         Instantiate(this.blood, hit.point, Quaternion.LookRotation(hit.normal));
     }
     if (damage > this.health)
     {
         this.health = 0;
     }
     else
     {
         this.health -= damage;
     }
     if (this.health == 0)
     {
         if (this.onDeath != null)
         {
             this.onDeath.Invoke();
         }
         Destroyable destroyable = this.GetComponent <Destroyable>();
         if (destroyable)
         {
             destroyable.Explode(hit.point);
         }
         else
         {
             Destroy(this.gameObject);
         }
     }
 }
Ejemplo n.º 3
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         RaycastHit hit;
         if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit))
         {
             Debug.DrawLine(Camera.main.transform.position, hit.point, Color.red);
             Actable actable = hit.transform.GetComponentInChildren <Actable>();
             if (actable)
             {
                 actable.Act(new string[] { "Foo" });
             }
             Deformable deformable = hit.transform.GetComponentInChildren <Deformable>();
             if (deformable)
             {
                 deformable.Hit(hit, Camera.main.transform.forward * 4.0f);
             }
             Destroyable destroyable = hit.transform.GetComponentInChildren <Destroyable>();
             if (destroyable)
             {
                 destroyable.Explode(hit.point);
             }
             Terminatable terminatable = hit.transform.GetComponentInChildren <Terminatable>();
             if (terminatable)
             {
                 terminatable.Hit(Random.Range(0, 47), this.transform);
             }
             Damageable damageable;
             if ((damageable = hit.transform.GetComponent <Damageable>()) != null || (damageable = hit.transform.root.GetComponent <Damageable>()) != null)
             {
                 damageable.Damage(hit);
             }
             Rigidbody rigidbody = hit.transform.GetComponentInChildren <Rigidbody>();
             if (rigidbody)
             {
                 rigidbody.AddForceAtPosition(Camera.main.transform.forward * 100.0f, hit.point);
             }
         }
     }
 }