示例#1
0
    public void Launch(Vector3 from)
    {
        if (!reloadedObject.gameObject.activeInHierarchy)
        {
            reloadedObject.gameObject.SetActive(true);
            reloadedObject.transform.position = transform.position;
        }

        if (reloadedObject.objectState != ObjectState.InAir)
        {
            reloadedObject.StateChange(ObjectState.InAir);
        }
        if ((reloadedObject.objectTag & (int)(ObjectTag.Projectile)) == 0)
        {
            reloadedObject.objectTag += (int)(ObjectTag.Projectile);
        }


        Rigidbody2D rb2d = reloadedObject.GetComponent <Rigidbody2D>();

        if (rb2d)
        {
            Vector2 force = (transform.position - from) * launchSpeed;
            rb2d.AddForce(force, ForceMode2D.Impulse);
        }
    }
示例#2
0
    void ThrowObject()
    {
        if (Input.GetKey(KeyCode.Mouse0))
        {
            Vector3 v3 = Input.mousePosition;
            v3.z = 10.0f;
            if (!onDrawLine)
            {
                throwStart = Camera.main.ScreenToWorldPoint(v3);
                onDrawLine = true;
            }

            throwEnd = Camera.main.ScreenToWorldPoint(v3);
        }
        else
        {
            if (onDrawLine)
            {
                onDrawLine = false;

                if (objectBasic && objectBasic.transform.parent == transform)
                {
                    objectBasic.transform.parent = null;

                    Vector2 v2 = throwStart - throwEnd;
                    objectBasic.StateChange(ObjectState.Free);
                    objectBasic.AddVelocity(v2 * 2, ForceMode2D.Impulse);

                    objectBasic = null;
                }
            }
        }
    }
示例#3
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        ObjectBasic obj = collision.GetComponent <ObjectBasic>();

        if (obj)
        {
            if (obj.objectTag.isObjectTagIncluded(ObjectTag.AttachAble))
            {
                obj.transform.parent   = transform;
                obj.transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + .1f);
                WheelJoint2D joint2D = GetComponent <WheelJoint2D>();
                if (joint2D)
                {
                    Rigidbody2D rb2d = obj.GetComponent <Rigidbody2D>();
                    if (rb2d)
                    {
                        joint2D.connectedBody = rb2d;
                        obj.StateChange(ObjectState.FixedDynamic);
                        if (obj.objectTag.isObjectTagIncluded(ObjectTag.Projectile))
                        {
                            obj.objectTag -= (int)ObjectTag.Projectile;
                        }
                    }
                    else
                    {
                        Debug.Log(transform.ToString() + ".OnTriggerEnter2D : !rb2d");
                    }
                }
                else
                {
                    Debug.Log("! joint2D");
                }
            }
        }
    }
示例#4
0
    public void GrabObject()
    {
        if (itemDetector.objectBasic)
        {
            objectBasic = itemDetector.objectBasic;
            itemDetector.objectBasic = null;

            objectBasic.transform.parent = transform;
            objectBasic.StateChange(ObjectState.FixedKinematic);
        }
    }
示例#5
0
    void ReloadBullet()
    {
        if (launcher && ammo && (state & (int)TurretState.Reloading) == 0)
        {
            ObjectBasic obj = ammo.GetInActivatedObject();
            obj.transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + .1f);

            if (obj.objectState != ObjectState.FixedKinematic)
            {
                obj.StateChange(ObjectState.FixedKinematic);
            }

            obj.gameObject.SetActive(true);
            launcher.reloadedObject = obj;
            if ((state & (int)TurretState.Reloading) == 0)
            {
                state += (int)TurretState.Reloading;
            }
        }
    }