物品展示必备代码(旋转与缩放代码…

来源:互联网 发布:期货日内交易策略源码 编辑:程序博客网 时间:2024/05/17 03:41
using UnityEngine;  
 
 
public class MouseFollowRotation : MonoBehaviour{  
 
 
    publicTransformtarget;              
 
    public floatxSpeed=200, ySpeed=200,mSpeed=10;  
 
    public floatyMinLimit=-50,yMaxLimit=50;  
 
    public floatdistance=7, minDistance=2,maxDistance=30;  
 
 
    //boolneedDamping = false;  
 
    public boolneedDamping=true;   
 
    floatdamping = 5.0f;  
 
 
    public floatx = 0.0f;  
 
    public floaty = 0.0f;  
 
 
 
    public voidSetTarget( GameObject go)  
 
 
 
    
 
       target = go.transform;  
 
    
 
    // Use thisfor initialization  
 
    void Start() {  
 
       Vector3 angles =transform.eulerAngles;  
 
       x = angles.y;  
 
       y = angles.x;  
 
    
 
 
    // Update iscalled once per frame  
 
    voidLateUpdate()   
 
    
 
 
 
       if(target)   
 
        
 
       //use the light button of mouse to rotate thecamera  
 
           if( Input.GetMouseButton(0))  
 
            
 
               x += Input.GetAxis("Mouse X") * xSpeed *0.02f;  
 
               y -= Input.GetAxis("Mouse Y") * ySpeed *0.02f;  
 
 
               y = ClampAngle(y, yMinLimit,yMaxLimit);  
 
 
               //print(Input.GetAxis("MouseX"));  
 
               //print( Input.GetAxis("MouseY"));  
 
               //print(x);  
 
               //print(y);  
 
 
               //Unity3D教程手册:[url]www.unitymanual.com[/url]
 
 
             
 
 
 
            distance -= Input.GetAxis("MouseScrollWheel")*mSpeed;  
 
           distance = Mathf.Clamp(distance, minDistance,maxDistance);  
 
 
 
           Quaternion rotation = Quaternion.Euler(y, x,0.0f);  
 
           Vector3 disVector = new Vector3( 0.0f, 0.0f, -distance);  
 
           Vector3 position = rotation * disVector +target.position;  
 
           //adjust the camera  
 
           if( needDamping )  
 
            
 
               transform.rotation = Quaternion.Lerp(transform.rotation, rotation,Time.deltaTime*damping);  
 
               transform.position = Vector3.Lerp(transform.position, position,Time.deltaTime*damping);  
 
            
 
           else 
 
            
 
               transform.rotation =rotation;  
 
               transform.position =position;  
 
            
 
             //Unity3D教程手册:[url]www.unitymanual.com[/url]
 
 
        
 
    
 
 
    static floatClampAngle (float angle, float min, floatmax)   
 
    
 
    if (angle< -360)  
 
       angle += 360;  
 
    if (angle> 360)  
 
       angle -= 360;  
 
    returnMathf.Clamp (angle, min,max);  
 
    
 
0 0
原创粉丝点击