示例#1
0
    public void Attack(AttackingObject attackingObject)
    {
        switch (attackingObject.type)
        {
        case AttackTypes.PistolShot:
            t = attackingObject.transform;
            GameObject.Instantiate(pistolShotEffect, t.position, t.rotation);
            RaycastHit hit;

            if (Physics.Raycast(attackingObject.transform.position, attackingObject.transform.forward, out hit,
                                attackingObject.range))
            {
                Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
                if (hit.collider.gameObject.CompareTag("Damagable"))
                {
                    hit.collider.GetComponent <DamagableObject>().RemoveHP(attackingObject.damage);
                }
            }


            break;

        default:
            Debug.LogError("Undefined attack");
            break;
        }
    }
示例#2
0
 void Start()
 {
     parent          = transform.parent;
     attackingObject = parent.GetComponent <AttackingObject>();
     if (attackingObject == null)
     {
         parent          = parent.parent;
         attackingObject = parent.GetComponent <AttackingObject>();
     }
 }
示例#3
0
 void Start()
 {
     parent          = transform.parent;
     parentComponent = parent.GetComponent <AttackingObject>();
     if (parentComponent == null)
     {
         parent          = parent.parent;
         parentComponent = parent.GetComponent <AttackingObject>();
     }
     spellUnits = parentComponent.spellUnits;
 }
示例#4
0
 void Start()
 {
     parent          = transform.parent;
     attackingObject = parent.GetComponent <AttackingObject>();
     if (attackingObject == null)
     {
         parent          = parent.parent;
         attackingObject = parent.GetComponent <AttackingObject>();
     }
     meleeUnits = attackingObject.meleeUnits;
     rangeUnits = attackingObject.rangeUnits;
 }
示例#5
0
    public void Attack(AttackingObject attackingObject)
    {
        switch (attackingObject.type)
        {
        case AttackTypes.PistolShot:
            t = attackingObject.transform;
            if (PhotonNetwork.IsConnected)
            {
                PhotonNetwork.Instantiate(pistolShotEffect.name, t.position, t.rotation);
            }
            else
            {
                GameObject.Instantiate(pistolShotEffect, t.position, t.rotation);
            }
            RaycastHit hit;

            if (Physics.Raycast(attackingObject.transform.position, attackingObject.transform.forward, out hit,
                                attackingObject.range))
            {
                Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance,
                              Color.yellow);
                if (hit.collider.gameObject.CompareTag("Damagable"))
                {
                    hit.collider.GetComponent <DamagableObject>().RemoveHP(attackingObject.damage);
                }
            }


            break;

        case AttackTypes.BazookaShot:
            t = attackingObject.transform;
            if (PhotonNetwork.IsConnected)
            {
                prefab = PhotonNetwork.Instantiate(bazookaShotEffect.name, t.position, t.rotation);
            }
            else
            {
                prefab = GameObject.Instantiate(bazookaShotEffect, t.position, t.rotation);
            }

            prefab.GetComponent <Rigidbody>().velocity = t.forward * attackingObject.speed;

            break;

        case AttackTypes.SwordSwing:
            t = attackingObject.transform;
            if (PhotonNetwork.IsConnected)
            {
                PhotonNetwork.Instantiate(swordSwingEffect.name, t.position, t.rotation);
            }
            else
            {
                GameObject.Instantiate(swordSwingEffect, t.position, t.rotation);
            }
            break;

        default:
            Debug.LogError("Undefined attack");
            break;
        }
    }