Exemplo n.º 1
0
    void ShootRay()
    {
        if (hitObject)
        {
            return;
        }



        if (Physics.Raycast(raySpawn, transform.forward, out hit, rayDistance + 1))
        {
            hitObject = true;

            //-----------------------
            SurfaceData surfData = hit.transform.root.GetComponent <SurfaceData>();
            if (surfData != null)
            {
                GameObject impactFX = (GameObject)Instantiate(particalEffects[surfData.surfaceMaterial], hit.point, Quaternion.identity);

                impactFX.transform.up = hit.normal;
                impactFX.transform.SetParent(hit.transform);
            }

            IDamagable damagable = hit.transform.root.GetComponent <IDamagable>();
            if (damagable != null)
            {
                damagable.ITakeDamage(25);
            }
            Debug.Log("Hit: " + hit.transform.name);
        }
        currentRaySpawn += rayMultiplier;
        Debug.DrawLine(raySpawn, raySpawn + transform.forward * rayMultiplier, Color.green, 2f * Time.deltaTime);
        raySpawn = raySpawn + (-transform.up * bulletDrop);
        raySpawn = raySpawn + (transform.forward * rayMultiplier); //rayMultiplier was originally currentRaySpawn
    }
Exemplo n.º 2
0
    public void AttackTarget(Transform target)
    {
        IHaveStrength _myStats = GetComponent <IHaveStrength>();

        if (_myStats != null)
        {
            if (!isAttacking)
            {
                isAttacking = true;
                StartCoroutine(AttackCooldown());

                IHaveHealth _stats = target.GetComponent <IHaveHealth>();
                if (_stats != null)
                {
                    if (_stats.Health > 0)
                    {
                        //Do damage
                        IDamagable _takeDamage = target.GetComponent <IDamagable>();
                        if (_takeDamage != null)
                        {
                            _takeDamage.ITakeDamage(_myStats.Strength, _stats);
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 3
0
 void DoDamage()
 {
     Debug.Log("Damage");
     foreach (GameObject _target in targetsInRange)
     {
         IDamagable damagable = _target.GetComponent <IDamagable>();
         if (damagable != null)
         {
             damagable.ITakeDamage(25);
         }
     }
     foreach (GameObject _target in targetsToRemove)
     {
         targetsInRange.Remove(_target);
     }
     targetsToRemove.Clear();
 }