コード例 #1
0
    // Start is called before the first frame update
    void Update()
    {
        shootableMask = LayerMask.GetMask("PropCol");
        gunLine       = GetComponent <LineRenderer>();

        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;
        gunLine.SetPosition(0, transform.position);

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            //hit an enemy goes here
            gunLine.SetPosition(1, shootHit.point); // draw line from position of fired all the way to hit point
            Debug.Log(gameObject.name + " 2DRaycasthit: " + shootHit.collider.name);

            GameObject     targetObj            = shootHit.collider.gameObject;
            MechCharStatHP targetMechCharStatHP = targetObj.GetComponent <MechCharStatHP>();
            if (targetMechCharStatHP)
            {
                targetMechCharStatHP.ApplyDamage(damage);
            }

            MechExtraCharSkillPhysicsShortcuts.LaunchObjBy2Transforms(shootHit.collider.transform, transform, pushBackForce);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
//        shootHit.collider.GetComponent<MechCharStatHP>().ApplyDamage(damage);
    }
コード例 #2
0
    // Start is called before the first frame update
    void Start()
    {
        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;
        gunLine.SetPosition(0, transform.position);
        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            //hit an enemy goes here
            gunLine.SetPosition(1, shootHit.point); // draw line from position of fired all the way to hit point
            Debug.Log(gameObject.name + " 2DRaycasthit: " + shootHit.collider.name);

            targetObj = shootHit.collider.gameObject;
            if (targetObj.tag == "Enemy" || targetObj.tag == "Enemy_2" && targetObj != shooter)
            {
                MechCharStatHP targetMechCharStatHP = targetObj.GetComponent <MechCharStatHP>();
                if (targetMechCharStatHP)
                {
                    targetMechCharStatHP.ApplyDamage(1000f);
                    print("Applying dmg: " + damage + " to " + targetObj.name);
                }
            }
            MechExtraCharSkillPhysicsShortcuts.LaunchObjBy2Transforms(shootHit.collider.transform, transform, pushBackForce);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
//        shootHit.collider.GetComponent<MechCharStatHP>().ApplyDamage(damage);
    }
コード例 #3
0
 private void OnCollisionEnter2D(Collision2D other)
 {
     if (other.gameObject)
     {
         MechCharStatHP mechCharStatHPComp = other.gameObject.GetComponent <MechCharStatHP>();
         if (mechCharStatHPComp)
         {
             mechCharStatHPComp.ApplyDamage(dmg);
         }
     }
 }
コード例 #4
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other)
     {
         MechCharStatHP mechCharStatHPComp = other.GetComponent <MechCharStatHP>();
         if (mechCharStatHPComp)
         {
             mechCharStatHPComp.ApplyDamage(dmg);
         }
     }
 }
コード例 #5
0
    public void UseItemAbility()
    {
        //sphr cast and attack all objects with PropCol layerMask in it
        if (nextMelee < Time.time)
        {
            nextMelee = Time.time + fireRate;

            //do damage
            if (bIs2DGame) // for 2D Games
            {
                Collider2D[] target = Physics2D.OverlapCircleAll(transform.position, knockBackRadius, shootableMask);

                if (bDebugTrace)
                {
                    DebugExtension.DebugWireSphere(transform.position, Color.red, knockBackRadius);
                }

                foreach (Collider2D tCol in target)
                {
                    MechCharStatHP targetMechCharStatHP = tCol.GetComponent <MechCharStatHP>();
                    if (targetMechCharStatHP)
                    {
                        targetMechCharStatHP.ApplyDamage(damage);
                        MechExtraCharSkillPhysicsShortcuts.LaunchObjBy2Transforms(tCol.gameObject.transform, transform, pushBackForce);
                    }
                }
            }

            else // for 3D Games
            {
                Collider[] target = Physics.OverlapSphere(transform.position, knockBackRadius, shootableMask);

                if (bDebugTrace)
                {
                    DebugExtension.DebugWireSphere(transform.position, Color.red, knockBackRadius);
                }
                print(target.Length);

                foreach (Collider tCol in target)
                {
                    MechCharStatHP targetMechCharStatHP = tCol.GetComponent <MechCharStatHP>();
                    if (targetMechCharStatHP)
                    {
                        targetMechCharStatHP.ApplyDamage(damage);
                        MechExtraCharSkillPhysicsShortcuts.LaunchObjBy2Transforms(tCol.gameObject.transform, transform, pushBackForce);
                    }
                }
            }
        }
    }
コード例 #6
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.layer == LayerMask.NameToLayer("PropCol"))
        {
            MechCharStatHP mechCharStatHP = other.gameObject.GetComponent <MechCharStatHP>();
            if (mechCharStatHP)
            {
                mechCharStatHP.ApplyDamage(damage);
            }
            myRB.velocity = Vector2.zero;
            MechExtraCharSkillPhysicsShortcuts.LaunchObjBy2Transforms(other.transform, transform, pushBackForce);

            Destroy(gameObject);
        }
    }
コード例 #7
0
    void Attack(GameObject targetObj)
    {
        MechCharStatHP targetMechCharStatHP = targetObj.GetComponent <MechCharStatHP>();

        if (targetMechCharStatHP != null)
        {
            if (fireRate <= Time.time)
            {
                targetMechCharStatHP.ApplyDamage(damage);
                fireRate = Time.time + damageRate;

                MechExtraCharSkillPhysicsShortcuts.LaunchObjBy2Transforms(targetObj.transform, transform, pushBackForce);
            }
        }
    }
コード例 #8
0
    // Start is called before the first frame update
    void Update()
    {
        shootableMask = LayerMask.GetMask("PropCol");
        gunLine       = GetComponent <LineRenderer>();
        gunLine.SetPosition(0, transform.position);

        // invert direction check
        if (bInvertRaycastDirection)
        {
            offsetMultiplier = -Mathf.Abs(offsetMultiplier); // right
        }
        else
        {
            offsetMultiplier = Mathf.Abs(offsetMultiplier); // right
        }

        shootHit = Physics2D.Raycast(transform.position, transform.right * offsetMultiplier, range, shootableMask);
        if (shootHit.collider != null)
        {
            gunLine.SetPosition(1, shootHit.point);
            Debug.Log(gameObject.name + " 2DRaycasthit: " + shootHit.collider.name);


            GameObject     targetObj            = shootHit.collider.gameObject;
            MechCharStatHP targetMechCharStatHP = targetObj.GetComponent <MechCharStatHP>();

            if (targetMechCharStatHP)
            {
                targetMechCharStatHP.ApplyDamage(damage);
            }

            MechExtraCharSkillPhysicsShortcuts.LaunchObjBy2Transforms(shootHit.collider.transform, transform, pushBackForce);
        }
        else
        {
            gunLine.SetPosition(1, transform.position + transform.right * range * offsetMultiplier);
        }
    }