private void Update() { if (Input.GetKeyDown(KeyCode.P)) { this.panel_enabled = !this.panel_enabled; } if (Input.GetKey(KeyCode.Period)) { MouseOrbitCS mouseOrbitCS = base.GetComponent(typeof(MouseOrbitCS)) as MouseOrbitCS; mouseOrbitCS.distance += 1f; if (mouseOrbitCS.distance > 150f) { mouseOrbitCS.distance = 150f; } } if (Input.GetKey(KeyCode.Comma)) { MouseOrbitCS mouseOrbitCS2 = base.GetComponent(typeof(MouseOrbitCS)) as MouseOrbitCS; mouseOrbitCS2.distance -= 1f; if (mouseOrbitCS2.distance < 30f) { mouseOrbitCS2.distance = 30f; } } }
void Update() { if (Input.GetKeyDown(KeyCode.P)) { panel_enabled = !panel_enabled; } if (Input.GetKey(KeyCode.Period)) { MouseOrbitCS script = GetComponent(typeof(MouseOrbitCS)) as MouseOrbitCS; script.distance += 1f; if (script.distance > 150) { script.distance = 150; } } if (Input.GetKey(KeyCode.Comma)) { MouseOrbitCS script = GetComponent(typeof(MouseOrbitCS)) as MouseOrbitCS; script.distance -= 1f; if (script.distance < 30) { script.distance = 30; } } }
private void LateUpdate() { if (this.target && !Input.GetKey(KeyCode.F)) { if (!Input.GetMouseButton(0)) { this.x += Input.GetAxis("Mouse X") * this.xSpeed * 0.02f; this.y -= Input.GetAxis("Mouse Y") * this.ySpeed * 0.02f; } this.y = MouseOrbitCS.ClampAngle(this.y, this.yMinLimit + this.normal_angle, this.yMaxLimit + this.normal_angle); Quaternion rotation = Quaternion.Euler(this.y, this.x, 0f); Vector3 position = rotation * new Vector3(0f, 0f, -this.distance) + this.target.position; base.transform.rotation = rotation; base.transform.position = position; } }
// Update is called once per frame void Update() { Vector3 pos = target.transform.position; Vector3 lpos = target.transform.position; Vector3 normal = Vector3.up; Camera camera = Camera.main; get_ground_pos(ref pos, ref normal, Vector3.up, ground_layerMask); Quaternion target_rot = target.transform.rotation; target_rot.eulerAngles = new Vector3(0, camera.transform.rotation.eulerAngles.y, 0); target.transform.rotation = target_rot; //Debug.Log(target.transform.rotation.eulerAngles); pos.x = lpos.x; pos.y = lpos.y; pos.z = lpos.z; get_ground_pos(ref pos, ref normal, normal, ground_layerMask); //pos=Vector3.Project(lpos, normal); Vector3 flat_forward = camera.transform.forward; flat_forward.y = 0; MouseOrbitCS mo = gameObject.GetComponent <MouseOrbitCS>(); mo.set_normal_angle(90 - Vector3.Angle(normal, flat_forward)); bool run = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); bool move = true; if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) { Vector3 vec = camera.transform.forward; vec.y = 0; vec.Normalize(); dir = Vector3.Cross(vec, normal); dir = Vector3.Cross(dir, normal); } else if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { Vector3 vec = camera.transform.right; vec.y = 0; vec.Normalize(); dir = Vector3.Cross(vec, normal); dir = Vector3.Cross(dir, normal); } else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { Vector3 vec = -camera.transform.right; vec.y = 0; vec.Normalize(); dir = Vector3.Cross(vec, normal); dir = Vector3.Cross(dir, normal); } else if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) { Vector3 vec = camera.transform.forward; vec.y = 0; vec.Normalize(); dir = Vector3.Cross(-vec, normal); dir = Vector3.Cross(dir, normal); } else { pos = lpos; move = false; } if (Input.GetKey(KeyCode.Comma)) { mo.distance += 6f * Time.deltaTime; if (mo.distance > maxdist) { mo.distance = maxdist; } } if (Input.GetKey(KeyCode.Period)) { mo.distance -= 6f * Time.deltaTime; if (mo.distance < mindist) { mo.distance = mindist; } } if (move) { if (run) { act_speed += (run_speed - act_speed) * 0.1f; } else { act_speed += (speed - act_speed) * 0.1f; } } else { act_speed += (0 - act_speed) * 0.1f; } pos += dir * act_speed * Time.deltaTime; if (pos.x < xmin) { pos.x = xmin; } else if (pos.x > xmax) { pos.x = xmax; } if (pos.z < zmin) { pos.z = zmin; } else if (pos.z > zmax) { pos.z = zmax; } //get_ground_pos(ref pos, ref normal, ground_layerMask); target.transform.position = pos; }