Ejemplo n.º 1
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.GetComponent <Controllable>())
        {
            controlledObject = other.GetComponent <Controllable>();

            if (!controlledObject.isControlled)
            {
                // Set as parent to stick to it
                transform.SetParent(controlledObject.transform);
                var newPosition = controlledObject.transform.position;
                newPosition.y      = transform.position.y;
                transform.position = newPosition;

                // Start controlling it
                controlledObject.isControlled = true;

                if (other.name == "Control Panel")
                {
                    accessing = AccessedObject.SteerAndGun;
                }
                else if (other.name == "Harpoon")
                {
                    accessing = AccessedObject.LightAndHarpoon;
                }
            }
            else
            {
                controlledObject = null;
            }
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    private void Update()
    {
        if (FindObjectOfType <Spaceship>().health <= 0)
        {
            return;
        }
        // Exit controlled object
        if (Input.GetButtonDown("Triangle"))
        {
            accessing = AccessedObject.Nothing;

            if (controlledObject)
            {
                // Unparent from controllable
                transform.SetParent(controlledObject.transform.parent);

                controlledObject.isControlled = false;
                controlledObject = null;
            }
        }

        switch (accessing)
        {
        case AccessedObject.SteerAndGun:
            var         input        = Input.GetAxis("LeftStickXAxis");
            const float fuelBurnRate = 5;

            if (input != 0)
            {
                spaceship.Rotate(Time.deltaTime * input);
                spaceship.fuel -= Time.deltaTime * fuelBurnRate;
            }

            FindObjectOfType <Fire>().UpdateInput();
            break;

        case AccessedObject.LightAndHarpoon:
            FindObjectOfType <RopeScript>().UpdateInput();
            if (!FindObjectOfType <RopeScript>().ropeOut)
            {
                ControlLight(GetRelativeStickDirection(Stick.Left));
            }
            break;

        case AccessedObject.Nothing:
            // Run around like a fool
            GetComponent <CharacterController>().Move(GetRelativeStickDirection(Stick.Left) * speed);
            break;

        default:
            // DON'T PUT ANYTHING HERE, WILL NEVER RUN
            break;
        }
    }
Ejemplo n.º 3
0
    private void OnTriggerExit(Collider other)
    {
        var controllable = other.GetComponent <Controllable>();

        // If by accident the player is knocked off the controllable, stop controlling it
        if (controllable && controlledObject == controllable && controllable.isControlled)
        {
            if (controlledObject)
            {
                // Unparent from controllable
                transform.SetParent(controlledObject.transform.parent);
                controlledObject = null;
            }

            controllable.isControlled = false;
            accessing = AccessedObject.Nothing;
        }
    }