예제 #1
0
    // Update is called once per frame
    void Update()
    {
        GetComponent <Rigidbody>().Sleep();
        if (!dead)
        {
            if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.Mouse0))
            {
                //Player movement
                transform.position = Vector3.MoveTowards(transform.position, waypoints[actualPoint].position, Time.deltaTime * playerSpeed);
                if (Vector3.Distance(this.transform.position, waypoints[actualPoint].position) < wayPointNear)
                {
                    if (actualPoint + 1 < waypoints.Count)
                    {
                        actualPoint++;
                    }
                }
            }

            //Player rotation
            Vector3 newForward = Vector3.Slerp(transform.forward, (waypoints[actualPoint].position - transform.position).normalized, Time.deltaTime * rotateSpeed);
            transform.forward = newForward;
        }
        else
        {
            cam.dead = true;
            if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.Mouse0))
            {
                Reset();
                Debug.Log("reset");
                cam.Reset();
            }
            else
            {
                //Player movement
                transform.position += new Vector3(1, 1, 1).normalized *dieForceNow;
                dieForceNow        *= dieForceModifier;
                dieForceNow         = Mathf.Max(0.5f, dieForceNow);

                //Player rotation
                Vector3 newForward = Vector3.Slerp(transform.forward, (cameraDeadtarget.position - transform.position).normalized, Time.deltaTime * rotateSpeed * 30);
                transform.forward = newForward;
            }
        }


        if (Input.GetKey(KeyCode.R))
        {
            Reset();
            cam.Reset();
        }
    }