• U3D场景摄像机旋转缩放



    var target : Transform;
    var xSpeed = 250.0;
    var ySpeed = 120.0;

    var yMinLimit = -20;
    var yMaxLimit = 80;

    var initDis = 20;
    var minDis = 3.0;
    var maxDis = 50.0;

    var wheelSpeed = 5;

    static var x = 0.0;
    static var y = 0.0;

    static  var distance;

    private var position;
    private var rotation;

    function Start () {

     x = 130;
     y = 30;
     

     transform.rotation = Quaternion.Euler(y, x, 0);;
     transform.position = Quaternion.Euler(y, x, 0) * Vector3(0.0, 0.0, -initDis) + target.position;

     // Make the rigid body not change rotation
        if (rigidbody)
      rigidbody.freezeRotation = true;

    }

    function Update () {
        if (target) {
      distance = Vector3.Distance(target.position,transform.position);
      if(Input.GetMouseButton(1)){
       x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
       y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
       
       y = ClampAngle(y, yMinLimit, yMaxLimit);
      }   
     
      distance-= Input.GetAxis("Mouse ScrollWheel")*wheelSpeed;    //获取鼠标中建响应
      distance = Mathf.Clamp(distance,minDis,maxDis);              //距离取最大值和最小值
     
      rotation = Quaternion.Euler(y, x, 0);
      position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
       
      transform.rotation = rotation;
      transform.position = position;
     
     }
    }

    static function ClampAngle (angle : float, min : float, max : float) {
     if (angle < -360)
      angle += 360;
     if (angle > 360)
      angle -= 360;
     return Mathf.Clamp (angle, min, max);
    }

  • 相关阅读:
    Single Number II
    Pascal's Triangle
    Remove Duplicates from Sorted Array
    Populating Next Right Pointers in Each Node
    Minimum Depth of Binary Tree
    Unique Paths
    Sort Colors
    Swap Nodes in Pairs
    Merge Two Sorted Lists
    Climbing Stairs
  • 原文地址:https://www.cnblogs.com/JimmyCode/p/2651863.html
Copyright © 2020-2023  润新知