Exemple #1
0
 // Use this for initialization
 void Start()
 {
     carScript = GetComponentInParent <CarControllerDemo>();
     ChangeLightState(0);
 }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.Tab))
        {
            controlsText.enabled = true;
        }
        else
        {
            controlsText.enabled = false;
        }

        if (canControl)
        {
            //Temporary fix to stop player from rotating after collision, which prevents ability to interact.
            if (anim.GetBool("isWalking") == false && anim.GetBool("walkback") == false)
            {
                rb.velocity = Vector3.zero;
            }

            if (activeVehicle != null && Vector3.Distance(transform.position, activeVehicle.transform.localPosition) >= 15f)
            {
                activeVehicle = null;
            }

            if (Input.GetKey(KeyCode.W))
            {
                anim.SetBool("isWalking", true);
                transform.Translate(Vector3.forward * speed * Time.deltaTime);
            }
            else
            {
                anim.SetBool("isWalking", false);
            }

            if (Input.GetKey(KeyCode.S))
            {
                anim.SetBool("walkback", true);
                transform.Translate(-Vector3.forward * speed * Time.deltaTime);
            }
            else
            {
                anim.SetBool("walkback", false);
            }

            if (Input.GetKey(KeyCode.A))
            {
                transform.Rotate(-Vector3.up * rotateSpeed * Time.deltaTime);
            }

            if (Input.GetKey(KeyCode.D))
            {
                transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime);
            }

            //// PRESS 'Q' TO TOGGLE KEYFOB CONTROLS \\\\
            if (Input.GetKeyDown(KeyCode.Q))
            {
                if (!fob)
                {
                    StartCoroutine("KeyFob", false);
                }
                else
                {
                    StartCoroutine("KeyFob", true);
                }
            }

            //// PRESS '1' TO WAVE AT CAMERA \\\\
            if (Input.GetKey(KeyCode.Alpha1))
            {
                head.LookAt(GameObject.Find("Main Camera").transform.position);
                anim.SetTrigger("Wave");
            }
        }

        //// VEHICLE INTERACTIONS \\\\
        if (Input.GetKeyDown(KeyCode.E) && activeVehicle != null)
        {
            switch (inCarState)
            {
            case 1:
                StartCoroutine("ExitCar");
                break;

            case 3:
                float distFromDoor = Vector3.Distance(transform.position, vehicleScript.exitPoint.position);
                if (nearHood)
                {
                    canControl = false;
                    StartCoroutine(MoveToPosition(vehicleScript.hoodPoint, 1f, 1f, "Hood"));
                }
                else if (nearTrunk)
                {
                    canControl = false;
                    StartCoroutine(MoveToPosition(vehicleScript.trunkPoint, 1f, 1f, "Trunk"));
                }
                else if (distFromDoor > .1f && distFromDoor < 10f)
                {
                    canControl = false;
                    vehicleScript.anim.SetBool("Bags", false);
                    StartCoroutine(MoveToPosition(vehicleScript.exitPoint, 1f, 1f, "Car"));
                }
                else if (distFromDoor <= .1f)
                {
                    vehicleScript.anim.SetBool("Bags", false);
                    vehicleScript.layinFrame = false;
                    transform.position       = vehicleScript.exitPoint.transform.position;
                    transform.rotation       = vehicleScript.exitPoint.transform.rotation;
                    StartCoroutine("EnterCar");
                }
                break;
            }
        }

        //// POP HOOD RELEASE FROM INSIDE CAR \\\\
        if (Input.GetKeyDown(KeyCode.Slash) && activeVehicle != null)
        {
            if (inCarState == 1)
            {
                vehicleScript.anim.SetTrigger("PopHood");
                vehicleScript.hoodPopped = true;
            }
        }

        //// OPEN TRUNK FROM INSIDE CAR \\\\
        if (Input.GetKeyDown(KeyCode.Backslash))
        {
            if (activeVehicle != null && inCarState == 1)
            {
                vehicleScript.anim.SetTrigger("OpenTrunk");
                vehicleScript.trunkUp = true;
            }
        }

        //// CHECK FOR OBJECTS IN FRONT OF PLAYER \\\\
        if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y + 1, transform.position.z), transform.TransformDirection(Vector3.forward), out hit, 10f))
        {
            switch (hit.collider.gameObject.tag)
            {
            case "Vehicle":
                activeVehicle = hit.collider.gameObject;
                vehicleScript = activeVehicle.GetComponent <CarControllerDemo>();
                break;
            }
        }

        //// KEYFOB CONTROLS \\\\
        if (fob)
        {
            if (Input.GetKeyDown(KeyCode.Keypad5) && !vehicleScript.trunkUp)
            {
                StartCoroutine("TrunkFob");
            }

            if (Input.GetKeyDown(KeyCode.Keypad7))
            {
                StartCoroutine("LockUnlockCar", false);
            }

            if (Input.GetKeyDown(KeyCode.Keypad9))
            {
                StartCoroutine("LockUnlockCar", true);
            }
        }
    }