Ejemplo n.º 1
0
    public void RunFloppyWithOutHeld(FloppySensor sensor)
    {
        Rigidbody rb = GetComponent <Rigidbody>();

        HeldItem hd = GameObject.Find("Character").GetComponent <Character>().HeldItem;

        if (hd.Rb == rb)
        {
            hd.Deattach();
        }

        Debug.Log("RunFloppyWithOutHeld.1 true");

        rb.isKinematic      = true;
        rb.detectCollisions = false;

        transform.SetParent(sensor.transform, true);

        PosA = transform.localPosition;
        PosB = new Vector3(0, 0, -1.0f);
        PosC = new Vector3(0, 0, 0.25f);
        RotA = transform.localRotation;
        RotB = Quaternion.Euler(180, 0, -90);

        Time      = 0.0f;
        MaxTime   = 0.5f;
        State     = 1;
        Direction = 1;

        //transform.localPosition = new Vector3(0,0, 0.25f);
        //transform.localRotation = Quaternion.Euler(180,0,-90);
    }
Ejemplo n.º 2
0
    public void WarpFloppy(FloppySensor sensor)
    {
        Rigidbody rb = GetComponent <Rigidbody>();

        HeldItem hd = GameObject.Find("Character").GetComponent <Character>().HeldItem;

        if (hd.Rb == rb)
        {
            hd.Deattach();
        }

        Debug.Log("WarpFloppy.1 true");

        rb.isKinematic      = true;
        rb.detectCollisions = false;

        transform.SetParent(sensor.transform, true);
        transform.localPosition = new Vector3(0, 0, 0.25f); //Vector3.Lerp(PosB, PosC, Time / MaxTime);
        transform.localRotation = Quaternion.Euler(180, 0, -90);

        sensor.IsEmpty = false;
        sensor.Floppy  = this;
        DX8.dx8 dx8 = GameObject.Find("DX8").GetComponent <DX8.dx8>();
        dx8.SetEjectButton(true);
    }
Ejemplo n.º 3
0
    void Update()
    {
        if (Dx8.IsPaused)
        {
            return;
        }

        if (FreezeState == FreezeState.Frozen)
        {
            return;
        }

        if (FreezeState == FreezeState.None)
        {
            RaycastHit hit;

            if (HeldItem.IsHolding())
            {
                if (Input.GetMouseButtonUp(0))
                {
                    HeldItem.Deattach();
                }
                else
                {
                    Vector3 moveTarget = Vector3.zero;

                    Ray ray = Camera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));

                    if (Physics.Raycast(ray, out hit, 100.0f, 1 << 8))
                    {
                        //moveTarget = hit.point;
                        HeldItem.TargetPoint = hit.point;
                        // Almost right - need to take into held objects radius into account.
                    }
                    else
                    {
                        HeldItem.TargetPoint = ray.origin + ray.direction * 5.0f;
                    }
                }
            }
            else
            {
                bool press = (Input.GetMouseButtonUp(0));

                // Boolean Raycast(Vector3 origin, Vector3 direction, Single maxDistance, Int32 layerMask);
                // Physics.Raycast(
                Ray ray = Camera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
                //public static Boolean Raycast(Ray ray, out RaycastHit hitInfo, Single maxDistance, Int32 layerMask);
                if (Physics.Raycast(ray, out hit, 100.0f, 1 << 8))
                {
                    if (LastLookedAt != hit.collider.gameObject)
                    {
                        LastLookedAt = hit.collider.gameObject;

                        string text = string.Empty;

                        if (LastLookedAt.tag == "Floppy")
                        {
                            FloppyDisk3dItem floppy = LastLookedAt.GetComponent <FloppyDisk3dItem>();
                            text = floppy.Title;
                        }

                        // LookAtInfo.text = text;
                        Dx8.UserInterface.SetCaption(text);
                    }

                    if (press && hit.collider.name == "PowerButton")
                    {
                        Dx8.PowerButtonPressed();
                    }
                    else if (press && hit.collider.name == "FloppyButton")
                    {
                        Dx8.FloppySensor.Eject();
                        // UI_RemoveFloppy();
                    }
                    else if (press)
                    {
                        Rigidbody rb = hit.collider.GetComponent <Rigidbody>();

                        if (rb)
                        {
                            bool isFloppy = (rb.tag == "Floppy");

                            if (isFloppy || (!isFloppy && CanPickUpHeavy))
                            {
                                HeldItem.Attach(rb, hit.collider);
                            }
                        }
                    }
                }
                else
                {
                    if (LastLookedAt != null)
                    {
                        //LookAtInfo.text = string.Empty;
                        Dx8.UserInterface.SetCaption(string.Empty);
                        LastLookedAt = null;
                    }
                }
            }
        }

        Quaternion yawq = Quaternion.identity;

        if (FreezeState == FreezeState.None || FreezeState == FreezeState.LookOnly)
        {
            Yaw   += Input.GetAxis("Mouse X") * 2.5f;
            Pitch -= Input.GetAxis("Mouse Y") * 2.5f;

            Pitch = Mathf.Clamp(Pitch, -89.0f, 89.0f);

            yawq = Quaternion.Euler(0, Yaw, 0);


            transform.localRotation        = yawq;
            Camera.transform.localRotation = Quaternion.Euler(Pitch, 0, 0);
        }

        if (FreezeState == FreezeState.None)
        {
            Vector3 velocity = Vector3.zero;
            bool    didMove  = false;

            if (Input.GetKey(KeyCode.W))
            {
                velocity.z += 1.0f;
                didMove     = true;
            }
            else if (Input.GetKey(KeyCode.S))
            {
                velocity.z -= 1.0f;
                didMove     = true;
            }

            if (Input.GetKey(KeyCode.A))
            {
                velocity.x -= 1.0f;
                didMove     = true;
            }
            else if (Input.GetKey(KeyCode.D))
            {
                velocity.x += 1.0f;
                didMove     = true;
            }

            if (didMove == true)
            {
                const float kSpeed = 8.0f;

                Vector3 delta = velocity * kSpeed * Time.deltaTime;
                delta = yawq * delta;

                CC.Move(delta);
            }
        }
    }